Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8560] XMLDocument on Linux crashes with a Segmentation Fault #3645

Open
swift-ci opened this issue Aug 17, 2018 · 2 comments
Open

[SR-8560] XMLDocument on Linux crashes with a Segmentation Fault #3645

swift-ci opened this issue Aug 17, 2018 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-8560
Radar None
Original Reporter chriseidhof (JIRA User)
Type Bug
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: b8f34b45710fb5d926cd9a5b7f1aeb88

Issue 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).

@spevans
Copy link
Collaborator

spevans commented Aug 20, 2018

This is a potential fix: #1664 but there might be other underlying issues Ive missed.

@swift-ci
Copy link
Contributor Author

swift-ci commented Mar 1, 2019

Comment by Alexandru Tudose (JIRA)

I still can reproduce this issue using latest swift version in docker (swift 4.2.2). Here is my Docker file:

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

and the output is

Linking ./.build/x86_64-unknown-linux/debug/xml-problem
Removing intermediate container 276ab95b9820
 ---> 7b4fbe9232f4
Step 6/7 : RUN .build/debug/xml-problem
 ---> Running in 49335d03230f
*** Error in `.build/debug/xml-problem': free(): invalid pointer: 0x00005597e343adb7 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f9029b517e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f9029b5a37a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f9029b5e53c]
/usr/lib/x86_64-linux-gnu/libxml2.so.2(xmlFreeNode+0x25b)[0x7f902726433b]
/usr/lib/swift/linux/libFoundation.so($S10Foundation7XMLNodeCfd+0x34b)[0x7f902b8ab14b]
/usr/lib/swift/linux/libFoundation.so($S10Foundation10XMLElementCfD+0x9)[0x7f902b8a4229]
/usr/lib/swift/linux/libswiftCore.so(+0x3c909b)[0x7f902b13209b]
.build/debug/xml-problem(+0x18c2)[0x5597e2c698c2]
.build/debug/xml-problem(+0x1411)[0x5597e2c69411]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f9029afa830]
.build/debug/xml-problem(+0x11a9)[0x5597e2c691a9]
======= Memory map: ========

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants