swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.32k stars 10.34k forks source link

[SR-13191] XMLDocument.characterEncoding crashes if the encoding was not in the parsed string #55631

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-13191
Radar rdar://problem/76902422
Original Reporter steve.klassen (JIRA User)
Type Bug
Environment Ubuntu Linux using Swift 5.2.4.
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: cad0bbeba9e4946e8620ef9213d72704

Issue Description:

Specifically, I tried the following...

import Foundation
import FoundationXML
let s1 = "<tag>hi</tag>"
let doc = XMLDocument(xmlString: s1)
doc.characterEncoding

On the mac (Apple Swift version 5.2.4) this prints "UTF-8".

But on Linux (Swift version 5.2.4) this gives me a seg fault (signal 11). (In lldb it just says "Execution interrupted.")

I would assume that the correct answer would either be "UTF-8" or possibly nil given that no encoding was specified.

swift-ci commented 4 years ago

Comment by Steven W. Klassen (JIRA)

It appears that it is not recognizing it as valid XML. However, the constructor is not giving any indication of this. Specifically it is not throwing an exception, nor returning an error or nil. From the init description, and from the apple docs, it would seem it should be throwing an exception.

jakevossen5 commented 4 years ago

I am new to the Swift project (this would be my first contribution) - would this be a good first issue?

weissi commented 3 years ago

Still crashing in 5.3 and current Swift main

$ jw-docker-swift-main 
docker.io/swiftlang/swift:nightly-main-bionic
 ################################################################
 #                              #
 # Swift Nightly Docker Image                   #
 # Tag: swift-DEVELOPMENT-SNAPSHOT-2021-04-18-a         #
 #                              #
 ################################################################

root@0ae6b2f0fd1a:/Users/johannes/devel/swift-corelibs-foundation# swift
Welcome to Swift version 5.5-dev (LLVM fb5a91b4e892ed9, Swift f17142883421ec0).
Type :help for assistance.
  1> import Foundation 
  2. import FoundationXML 
  3. let s1 = "<tag>hi</tag>" 
  4. let doc = XMLDocument(xmlString: s1) 
  5. doc.characterEncoding
s1: String = {
  _guts = {
    _object = {
      _countAndFlagsBits = <extracting data from value failed>

      _object = <extracting data from value failed>

    }
  }
}
doc: XMLDocument = <extracting data from value failed>

Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)
weissi commented 3 years ago

@swift-ci create