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

encoding/xml: accepts names containing : followed by a character that cannot start a Name #68392

Open
Tracked by #68293
DemiMarie opened this issue Jul 11, 2024 · 2 comments · May be fixed by #69196
Open
Tracked by #68293

encoding/xml: accepts names containing : followed by a character that cannot start a Name #68392

DemiMarie opened this issue Jul 11, 2024 · 2 comments · May be fixed by #69196
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@DemiMarie
Copy link
Contributor

DemiMarie commented Jul 11, 2024

Go version

1.22

Output of go env in your module/workspace:

What is on https://go.dev/play as of when this issue is filed

What did you do?

Ran the following Go code:

package main

import (
	"encoding/xml"
	"fmt"
)

func main() {
	err := xml.Unmarshal([]byte(`<a:1/>`), new(interface{}))
	if err != nil {
		fmt.Printf("XML correctly rejected with error %#v", err)
	} else {
		fmt.Println("No error?")
	}
}

What did you see happen?

No error? displayed, indicating successful unmarshaling.

What did you expect to see?

Parsing should fail because a:1 isn’t a valid XML QName. This is because a QName is either one NCName (a Name with no :) or two NCNames separated by :. 1 isn’t a valid Name, so it isn’t a valid QName either.

The simplest fix (which will also fix #68393) is to remove : from the list of characters valid in a Name, and instead have nsname() work in two steps:

  1. Read a Name.
  2. Check if the next byte is :.
  3. If it is not, unread it.
  4. If it is, read another Name.
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 13, 2024
DemiMarie added a commit to DemiMarie/go that referenced this issue Sep 1, 2024
An XML QName is syntactically two Names separated by a colon, rather
than a single name that has a colon in it.  This fixes multiple bugs in
XML QName reading.

Fixes: golang#68294
Fixes: golang#68392
Fixes: golang#68393
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/609377 mentions this issue: encoding/xml: treat a namespaced name as two names, not one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants