Uploaded image for project: 'Swift'
  1. Swift
  2. SR-8560

XMLDocument on Linux crashes with a Segmentation Fault

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reopened
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Foundation
    • Labels:
      None

      Description

      Here's what I tried:

      import Foundation
      
      let str = """
      <?xml version="1.0" encoding="UTF-8"?>
      <plans></plans>
      """
      
      let data = str.data(using: .utf8)!
      
      func test() throws {
          guard let doc = try XMLDocument(data: data, options: []).rootElement() else { fatalError("Couldn't parse doc") }
          print(doc.name)
      }
      
      try test()
      
      

      I ran it on Linux with the following Dockerfile:

      FROM norionomura/swift:41
      WORKDIR /app
      COPY Package.swift ./
      COPY Sources ./Sources
      RUN swift build --product isolate-xml-problem --configuration debug
      RUN .build/debug/isolate-xml-problem
      CMD ["echo hello"]
      

      This crashes with the following error message:

      *** Error in `.build/debug/isolate-xml-problem': free(): invalid pointer: 0x0000560148211ff7 ***
      ======= Backtrace: =========
      /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fdc2946c7e5]
      /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fdc2947537a]
      /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fdc2947953c]
      /usr/lib/x86_64-linux-gnu/libxml2.so.2(xmlFreeNode+0x25b)[0x7fdc269772fb]
      /usr/lib/swift/linux/libFoundation.so(_T010Foundation7XMLNodeCfd+0x331)[0x7fdc2ace8fd1]
      /usr/lib/swift/linux/libFoundation.so(_T010Foundation10XMLElementCfD+0x9)[0x7fdc2ace11d9]
      /usr/lib/swift/linux/libswiftCore.so(+0x39f88b)[0x7fdc2b54488b]
      .build/debug/isolate-xml-problem(+0x1a1e)[0x5601468c6a1e]
      .build/debug/isolate-xml-problem(+0x1737)[0x5601468c6737]
      /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fdc29415830]
      .build/debug/isolate-xml-problem(+0x1259)[0x5601468c6259]
      

      The `test` method body does execute successfully, by the way (it prints the node's name).

      At the moment of writing, I can also replicate this with the nightly branch (change 41 to nightly in the Dockerfile).

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              chriseidhof Chris Eidhof
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: