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-12219] XML DTDs are completely broken #3268

Open
karwa opened this issue Feb 17, 2020 · 1 comment
Open

[SR-12219] XML DTDs are completely broken #3268

karwa opened this issue Feb 17, 2020 · 1 comment

Comments

@karwa
Copy link
Contributor

karwa commented Feb 17, 2020

Previous ID SR-12219
Radar rdar://problem/59655370
Original Reporter @karwa
Type Bug
Environment

Swift-corelibs-foundation:

97bfd79

Darwin Foundation:

macOS 10.15.2 (19C57)

Xcode 11.3.1 (11C504)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: c60cd4ad2b138e7548d0599e363d1c2a

Issue Description:

The swift-corelibs-foundation version of XML DTDs are just entirely broken.

1. Root document not set

let typedefs = XMLDTD()
let document = XMLDocument(rootElement: nil)
document.dtd = typedefs
print(typedefs.rootDocument) // nil -- huh?

This is the same on both Darwin and SCF, but it definitely looks like a bug.

2. Children not set

This means that basic entity substitutions (`&author;` -> "Robert Thompson") also do not work on SCF.

let typedefs = XMLDTD()
let ent = XMLNode.dtdNode(withXMLString:"<!ENTITY author 'Robert Thompson'>") as! XMLDTDNode
typedefs.addChild(ent)
        
let document = XMLDocument(rootElement: nil)
document.dtd = typedefs
print(typedefs.childCount)
print(typedefs.children?.count)
print("-----")
print(document)

SCF output (note that childCount != children.count):

0
Optional(1)
-----
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE  PUBLIC "" "">

Darwin output:

1
Optional(1)
-----
<!DOCTYPE  [
    <!ENTITY author "Robert Thompson">
]>

3. Adding copies of nodes crashes

let typedefs = XMLDTD()
let ent = XMLNode.dtdNode(withXMLString:"<!ENTITY author 'Robert Thompson'>") as! XMLDTDNode
typedefs.addChild(ent)
typedefs.addChild(ent.copy() as! XMLNode)
print(typedefs)

SCF output:

Crash in CFXMLInterface.c:_CFXMLNodeGetPrivateData (node is a null pointer)

Darwin output (no crash):

<!ENTITY author "Robert Thompson">
<!ENTITY (null) "Robert Thompson">

4. Makes a copy of the DTD node when it shouldn't

(note: we're using children.count rather than childCount to work around #2)

let document = XMLDocument(rootElement: nil)

let typedefs = XMLDTD()
document.dtd = typedefs

let ent = XMLNode.dtdNode(withXMLString:"<!ENTITY author 'Robert Thompson'>") as! XMLDTDNode
typedefs.addChild(ent)
print(document.dtd)
print(document.dtd?.children?.count)

SCF output:

Optional(<!DOCTYPE  PUBLIC "" "">)
Optional(0)

Darwin output:

Optional(    <!ENTITY author "Robert Thompson">
)
Optional(1)
@hborla
Copy link
Member

hborla commented Feb 21, 2020

@swift-ci create

@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