[go] encoding/xml: fix depth processing in unmarshal

9 views
Skip to first unread message

Ian Alexander (Gerrit)

unread,
Jul 21, 2026, 12:07:02 PMJul 21
to goph...@pubsubhelper.golang.org, Nicholas Husin, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
Attention needed from Nicholas Husin

New activity on the change

Open in Gerrit

Related details

Attention is currently required from:
  • Nicholas Husin
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
Gerrit-Change-Number: 803320
Gerrit-PatchSet: 3
Gerrit-Owner: Ian Alexander <ji...@google.com>
Gerrit-Reviewer: Ian Alexander <ji...@google.com>
Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
Gerrit-Attention: Nicholas Husin <n...@golang.org>
Gerrit-Comment-Date: Tue, 21 Jul 2026 16:06:58 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Ian Alexander (Gerrit)

unread,
Jul 21, 2026, 8:17:45 PMJul 21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Nicholas Husin

Ian Alexander uploaded new patchset

Ian Alexander uploaded patch set #4 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Nicholas Husin
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
Gerrit-Change-Number: 803320
Gerrit-PatchSet: 4
unsatisfied_requirement
satisfied_requirement
open
diffy

Nicholas Husin (Gerrit)

unread,
Jul 22, 2026, 1:00:27 AMJul 22
to Ian Alexander, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
Attention needed from Ian Alexander

Nicholas Husin added 3 comments

Patchset-level comments
File-level comment, Patchset 4 (Latest):
Nicholas Husin . unresolved

TryBots failure for `gotip-wasip1-wasm_wazero` looks real?

File src/encoding/xml/read.go
Line 156, Patchset 4 (Latest): return d.unmarshal(val.Elem(), start, d.unmarshalDepth)
Nicholas Husin . unresolved

Sorry, I'm not familiar with this package at all. But, I think this might be an incomplete fix?

It seems that `Decoder.unmarshalDepth` only keeps track of the `UnmarshalXML` method depth. So, a recursive XML structure where not all `structs` implement `UnmarshalXML` method can still bypass this limit:

```
type Section struct {
Sub *Section `xml:"section"`
Custom *Extension `xml:"extension"`
}
type Extension struct {
Body Section
}
func (e *Extension) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var body Section
if err := d.DecodeElement(&body, &start); err != nil {
return err
}
e.Body = body
return nil
}
func TestDecodeElementDepthBypass(t *testing.T) {
// Construct a document with 3 blocks of 5,000 nested <section> tags,
// separated by <extension> tags.
// Total XML nesting depth = 15,003 tags deep (maxUnmarshalDepth is 10,000).
openSections := strings.Repeat("<section>", 5000)
closeSections := strings.Repeat("</section>", 5000)
        var buf strings.Builder
for i := 0; i < 3; i++ {
buf.WriteString(openSections)
buf.WriteString("<extension>")
}
for i := 0; i < 3; i++ {
buf.WriteString("</extension>")
buf.WriteString(closeSections)
}
        var sec Section
err := xml.Unmarshal([]byte(buf.String()), &sec)
        if err == nil {
t.Fatalf("FAILED: Unmarshaled 15,003 levels deep without error (depth limit bypassed)")
}
```

In this case, after reaching a `depth` of 5000 inside the nested `<section>` tags, the `depth` gets reset back to `d.unmarshalDepth` (1, 2, then 3) whenever `<extension>` is encountered.

File src/encoding/xml/read_test.go
Line 1162, Patchset 4 (Latest): if runtime.GOARCH == "wasm" {
tests = []struct {
name string
depth int
wantErr error
}{
{
name: "wasm below limit",
depth: 4998,
wantErr: nil,
},
{
name: "wasm above limit",
depth: 4999,
wantErr: errUnmarshalDepth,
},
}
}
Nicholas Husin . unresolved

Probably cleaner to just define a `limit` variable that has different value according to `runtime.GOARCH`. Then, the test cases can define `depth` as `limit-1` and so on.

Open in Gerrit

Related details

Attention is currently required from:
  • Ian Alexander
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
    Gerrit-Change-Number: 803320
    Gerrit-PatchSet: 4
    Gerrit-Owner: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
    Gerrit-Attention: Ian Alexander <ji...@google.com>
    Gerrit-Comment-Date: Wed, 22 Jul 2026 05:00:21 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Ian Alexander (Gerrit)

    unread,
    Jul 22, 2026, 9:40:01 PMJul 22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Ian Alexander

    Ian Alexander uploaded new patchset

    Ian Alexander uploaded patch set #5 to this change.
    Following approvals got outdated and were removed:
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Alexander
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
    Gerrit-Change-Number: 803320
    Gerrit-PatchSet: 5
    unsatisfied_requirement
    open
    diffy

    Ian Alexander (Gerrit)

    unread,
    Jul 22, 2026, 9:41:01 PMJul 22
    to goph...@pubsubhelper.golang.org, Nicholas Husin, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
    Attention needed from Ian Alexander

    Ian Alexander voted and added 2 comments

    Votes added by Ian Alexander

    Commit-Queue+1

    2 comments

    File src/encoding/xml/read.go
    Line 156, Patchset 4: return d.unmarshal(val.Elem(), start, d.unmarshalDepth)
    Nicholas Husin . resolved
    Ian Alexander

    Done

    File src/encoding/xml/read_test.go
    Line 1162, Patchset 4: if runtime.GOARCH == "wasm" {

    tests = []struct {
    name string
    depth int
    wantErr error
    }{
    {
    name: "wasm below limit",
    depth: 4998,
    wantErr: nil,
    },
    {
    name: "wasm above limit",
    depth: 4999,
    wantErr: errUnmarshalDepth,
    },
    }
    }
    Nicholas Husin . resolved

    Probably cleaner to just define a `limit` variable that has different value according to `runtime.GOARCH`. Then, the test cases can define `depth` as `limit-1` and so on.

    Ian Alexander

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Alexander
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
    Gerrit-Change-Number: 803320
    Gerrit-PatchSet: 5
    Gerrit-Owner: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
    Gerrit-Attention: Ian Alexander <ji...@google.com>
    Gerrit-Comment-Date: Thu, 23 Jul 2026 01:40:57 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Nicholas Husin <n...@golang.org>
    unsatisfied_requirement
    open
    diffy

    Ian Alexander (Gerrit)

    unread,
    Jul 22, 2026, 10:07:41 PMJul 22
    to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Nicholas Husin, golang-co...@googlegroups.com

    Ian Alexander voted Commit-Queue+1

    Commit-Queue+1
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
    Gerrit-Change-Number: 803320
    Gerrit-PatchSet: 5
    Gerrit-Owner: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
    Gerrit-Comment-Date: Thu, 23 Jul 2026 02:07:32 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    open
    diffy

    Ian Alexander (Gerrit)

    unread,
    Jul 22, 2026, 11:02:07 PMJul 22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Ian Alexander

    Ian Alexander uploaded new patchset

    Ian Alexander uploaded patch set #6 to this change.
    Following approvals got outdated and were removed:
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Alexander
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
    Gerrit-Change-Number: 803320
    Gerrit-PatchSet: 6
    Gerrit-Owner: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
    Gerrit-Attention: Ian Alexander <ji...@google.com>
    unsatisfied_requirement
    open
    diffy

    Ian Alexander (Gerrit)

    unread,
    Jul 22, 2026, 11:02:35 PMJul 22
    to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Nicholas Husin, golang-co...@googlegroups.com

    Ian Alexander voted Commit-Queue+1

    Commit-Queue+1
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
    Gerrit-Change-Number: 803320
    Gerrit-PatchSet: 6
    Gerrit-Owner: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Ian Alexander <ji...@google.com>
    Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
    Gerrit-Comment-Date: Thu, 23 Jul 2026 03:02:31 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    open
    diffy

    Ian Alexander (Gerrit)

    unread,
    Jul 22, 2026, 11:42:13 PMJul 22
    to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Nicholas Husin, golang-co...@googlegroups.com
    Attention needed from Ian Alexander and Nicholas Husin

    Ian Alexander voted and added 1 comment

    Votes added by Ian Alexander

    Commit-Queue+1

    1 comment

    Patchset-level comments
    File-level comment, Patchset 4:
    Nicholas Husin . resolved

    TryBots failure for `gotip-wasip1-wasm_wazero` looks real?

    Ian Alexander

    Had to skip the test on wazero. LMK if you don't like the checking of GO_BUILDER_NAME.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Alexander
    • Nicholas Husin
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
      Gerrit-Change-Number: 803320
      Gerrit-PatchSet: 6
      Gerrit-Owner: Ian Alexander <ji...@google.com>
      Gerrit-Reviewer: Ian Alexander <ji...@google.com>
      Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
      Gerrit-Attention: Ian Alexander <ji...@google.com>
      Gerrit-Attention: Nicholas Husin <n...@golang.org>
      Gerrit-Comment-Date: Thu, 23 Jul 2026 03:42:08 +0000
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Nicholas Husin (Gerrit)

      unread,
      Jul 23, 2026, 12:54:01 PMJul 23
      to Ian Alexander, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
      Attention needed from Ian Alexander

      Nicholas Husin added 3 comments

      Commit Message
      Line 15, Patchset 6 (Latest):in the unmarshal method. When a custom UnmarshalXML method called
      Nicholas Husin . unresolved

      nit: extra space, probably from automatic line wrapping?

      Same before "This allowed documents".

      File src/encoding/xml/read.go
      Line 210, Patchset 6 (Parent): d.unmarshalDepth++
      Nicholas Husin . unresolved

      Should these be removed?

      I think this will cause the following to fail:

      ```
      type manualNode struct {
      Child *manualNode
      }
      func (m *manualNode) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
      for {
      tok, err := d.Token()
      if err != nil {
      return err
      }
      switch t := tok.(type) {
      case xml.StartElement:
      var child manualNode
      if err := d.DecodeElement(&child, &t); err != nil {
      return err
      }
      m.Child = &child
      case xml.EndElement:
      return nil
      }
      }
      }
      func TestManual(t *testing.T) {
      depth := 10001
      payload := bytes.Join([][]byte{
      bytes.Repeat([]byte("<a>"), depth),
      bytes.Repeat([]byte("</a>"), depth),
      }, nil)
              var node manualNode
      err := xml.Unmarshal(payload, &node)
      if err == nil {
      t.Fatalf("Unmarshal depth limit bypassed: unmarshaled 10,001 levels deep without error")
      }
      }
      ```

      If we do not increment `d.unmarshalDepth` here, when someone uses `Token` manually before calling `DecodeElement`, we would fail to account for the depth increase.

      Although, just adding back `d.unmarshalDepth++` and `d.unmarshalDepth--` increase here would mean that when someones calls `Decode` without `Token`, the depth would increase by 2 instead of 1 I think. Maybe that's fine since our depth limit is pretty high? It would probably be confusing if a user ever hits the limit though.

      File src/encoding/xml/read_test.go
      Line 1187, Patchset 6 (Latest):type Section struct {

      Sub *Section `xml:"section"`
      Custom *Extension `xml:"extension"`
      }

      type Extension struct {
      Body Section
      }
      Nicholas Husin . unresolved

      nit: no need to export `Section` and `Extension`. Doesn't matter that much since it's a test, but might as well be consistent. Renaming `Section` and `Extension` to be more descriptive for the test might be nice too.

      (I guess this was copied from my comment, my bad.)

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Ian Alexander
      Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
        Gerrit-Change-Number: 803320
        Gerrit-PatchSet: 6
        Gerrit-Owner: Ian Alexander <ji...@google.com>
        Gerrit-Reviewer: Ian Alexander <ji...@google.com>
        Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
        Gerrit-Attention: Ian Alexander <ji...@google.com>
        Gerrit-Comment-Date: Thu, 23 Jul 2026 16:53:54 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Ian Alexander (Gerrit)

        unread,
        Jul 23, 2026, 4:42:53 PMJul 23
        to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
        Attention needed from Ian Alexander

        Ian Alexander uploaded new patchset

        Ian Alexander uploaded patch set #7 to this change.
        Following approvals got outdated and were removed:

        Related details

        Attention is currently required from:
        • Ian Alexander
        Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: newpatchset
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
          Gerrit-Change-Number: 803320
          Gerrit-PatchSet: 7
          unsatisfied_requirement
          open
          diffy

          Ian Alexander (Gerrit)

          unread,
          Jul 23, 2026, 4:44:42 PMJul 23
          to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Nicholas Husin, golang-co...@googlegroups.com

          Ian Alexander voted and added 2 comments

          Votes added by Ian Alexander

          Commit-Queue+1

          2 comments

          Commit Message
          Line 15, Patchset 6:in the unmarshal method. When a custom UnmarshalXML method called
          Nicholas Husin . resolved

          nit: extra space, probably from automatic line wrapping?

          Same before "This allowed documents".

          Ian Alexander

          This is a byproduct of typewriter training in my youth, in which double-spaces after terminal punctuation were taught. With the advent of proportional fonts in computing, it seems to be now viewed as outdated (but not necessarily "incorrect").

          File src/encoding/xml/read_test.go
          Line 1187, Patchset 6:type Section struct {

          Sub *Section `xml:"section"`
          Custom *Extension `xml:"extension"`
          }

          type Extension struct {
          Body Section
          }
          Nicholas Husin . resolved

          nit: no need to export `Section` and `Extension`. Doesn't matter that much since it's a test, but might as well be consistent. Renaming `Section` and `Extension` to be more descriptive for the test might be nice too.

          (I guess this was copied from my comment, my bad.)

          Ian Alexander

          Done

          Open in Gerrit

          Related details

          Attention set is empty
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
          Gerrit-Change-Number: 803320
          Gerrit-PatchSet: 7
          Gerrit-Owner: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-Comment-Date: Thu, 23 Jul 2026 20:44:38 +0000
          unsatisfied_requirement
          open
          diffy

          Ian Alexander (Gerrit)

          unread,
          Jul 23, 2026, 4:56:06 PMJul 23
          to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
          Attention needed from Ian Alexander

          Ian Alexander uploaded new patchset

          Ian Alexander uploaded patch set #8 to this change.
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Ian Alexander
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: newpatchset
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
          Gerrit-Change-Number: 803320
          Gerrit-PatchSet: 8
          Gerrit-Owner: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-Attention: Ian Alexander <ji...@google.com>
          unsatisfied_requirement
          open
          diffy

          Ian Alexander (Gerrit)

          unread,
          Jul 23, 2026, 4:56:49 PMJul 23
          to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Nicholas Husin, golang-co...@googlegroups.com

          Ian Alexander voted Commit-Queue+1

          Commit-Queue+1
          Open in Gerrit

          Related details

          Attention set is empty
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
          Gerrit-Change-Number: 803320
          Gerrit-PatchSet: 8
          Gerrit-Owner: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-Comment-Date: Thu, 23 Jul 2026 20:56:45 +0000
          Gerrit-HasComments: No
          Gerrit-Has-Labels: Yes
          unsatisfied_requirement
          open
          diffy

          Roland Shoemaker (Gerrit)

          unread,
          Jul 23, 2026, 5:03:42 PMJul 23
          to Ian Alexander, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Nicholas Husin, golang-co...@googlegroups.com

          Roland Shoemaker added 5 comments

          File src/encoding/xml/read.go
          Roland Shoemaker

          Yeah I think we need to retain this, its interaction with the `unmarshal` `depth` argument is making everything more complicated though.

          Line 323, Patchset 6: oldDepth := d.unmarshalDepth
          d.unmarshalDepth = depth
          defer func() { d.unmarshalDepth = oldDepth }()
          Roland Shoemaker . unresolved

          I think we should probably just do away with the `depth` argument and move to always using `unmarshalDepth`, since it makes following this all a bit confusing.

          This way we'd remove the depth arg from unmarshal, unmarshalInterface,and unmarshalPath, and add

              unmarshalDepth++
          defer unmarshalDepth--

          to the preamble of each method.

          File src/encoding/xml/read_test.go
          Line 1162, Patchset 6: depth: maxDepth,
          Roland Shoemaker . unresolved

          If we switch to using only unmarshalDepth I believe this would need to be `(maxDepth/4)` and the below would be `(maxDepth/4)+1`, since the DecodeElement loop recurses in unmarshal ~4 times.

          Line 1226, Patchset 6: t.Fatalf("FAILED: Unmarshaled 15,003 levels deep without error (depth limit bypassed)")
          Roland Shoemaker . unresolved

          `Fatal`, since there are no formatting args.

          Line 1226, Patchset 6: t.Fatalf("FAILED: Unmarshaled 15,003 levels deep without error (depth limit bypassed)")
          Roland Shoemaker . unresolved

          You can remove this prefix.

          Open in Gerrit

          Related details

          Attention set is empty
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
          Gerrit-Change-Number: 803320
          Gerrit-PatchSet: 6
          Gerrit-Owner: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-CC: Roland Shoemaker <rol...@golang.org>
          Gerrit-Comment-Date: Thu, 23 Jul 2026 21:03:39 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          Comment-In-Reply-To: Nicholas Husin <n...@golang.org>
          unsatisfied_requirement
          open
          diffy

          Ian Alexander (Gerrit)

          unread,
          Jul 23, 2026, 5:06:40 PMJul 23
          to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
          Attention needed from Ian Alexander

          Ian Alexander uploaded new patchset

          Ian Alexander uploaded patch set #9 to this change.
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Ian Alexander
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: newpatchset
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
          Gerrit-Change-Number: 803320
          Gerrit-PatchSet: 9
          Gerrit-Owner: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-CC: Roland Shoemaker <rol...@golang.org>
          Gerrit-Attention: Ian Alexander <ji...@google.com>
          unsatisfied_requirement
          open
          diffy

          Ian Alexander (Gerrit)

          unread,
          Jul 23, 2026, 5:07:34 PMJul 23
          to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Roland Shoemaker, Nicholas Husin, golang-co...@googlegroups.com

          Ian Alexander voted Commit-Queue+1

          Commit-Queue+1
          Open in Gerrit

          Related details

          Attention set is empty
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
          Gerrit-Change-Number: 803320
          Gerrit-PatchSet: 9
          Gerrit-Owner: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-CC: Roland Shoemaker <rol...@golang.org>
          Gerrit-Comment-Date: Thu, 23 Jul 2026 21:07:31 +0000
          Gerrit-HasComments: No
          Gerrit-Has-Labels: Yes
          unsatisfied_requirement
          open
          diffy

          Ian Alexander (Gerrit)

          unread,
          Jul 23, 2026, 5:14:20 PMJul 23
          to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
          Attention needed from Ian Alexander

          Ian Alexander uploaded new patchset

          Ian Alexander uploaded patch set #10 to this change.
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Ian Alexander
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: newpatchset
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
          Gerrit-Change-Number: 803320
          Gerrit-PatchSet: 10
          Gerrit-Owner: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-CC: Roland Shoemaker <rol...@golang.org>
          Gerrit-Attention: Ian Alexander <ji...@google.com>
          unsatisfied_requirement
          open
          diffy

          Ian Alexander (Gerrit)

          unread,
          Jul 23, 2026, 5:14:36 PMJul 23
          to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Roland Shoemaker, Nicholas Husin, golang-co...@googlegroups.com

          Ian Alexander voted and added 2 comments

          Votes added by Ian Alexander

          Commit-Queue+1

          2 comments

          File src/encoding/xml/read_test.go
          Line 1226, Patchset 6: t.Fatalf("FAILED: Unmarshaled 15,003 levels deep without error (depth limit bypassed)")
          Roland Shoemaker . resolved

          `Fatal`, since there are no formatting args.

          Ian Alexander

          Done

          Line 1226, Patchset 6: t.Fatalf("FAILED: Unmarshaled 15,003 levels deep without error (depth limit bypassed)")
          Roland Shoemaker . resolved

          You can remove this prefix.

          Ian Alexander

          Done

          Open in Gerrit

          Related details

          Attention set is empty
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
          Gerrit-Change-Number: 803320
          Gerrit-PatchSet: 10
          Gerrit-Owner: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Ian Alexander <ji...@google.com>
          Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
          Gerrit-CC: Roland Shoemaker <rol...@golang.org>
          Gerrit-Comment-Date: Thu, 23 Jul 2026 21:14:31 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: Yes
          Comment-In-Reply-To: Roland Shoemaker <rol...@golang.org>
          unsatisfied_requirement
          open
          diffy

          Ian Alexander (Gerrit)

          unread,
          Jul 23, 2026, 5:32:25 PMJul 23
          to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Roland Shoemaker, Nicholas Husin, golang-co...@googlegroups.com
          Attention needed from Nicholas Husin and Roland Shoemaker

          Ian Alexander added 3 comments

          File src/encoding/xml/read.go
          Nicholas Husin . resolved
          Ian Alexander

          I think I have a better solution for tracking depth by updating it within the push and pop methods on the decoder.

          Line 323, Patchset 6: oldDepth := d.unmarshalDepth
          d.unmarshalDepth = depth
          defer func() { d.unmarshalDepth = oldDepth }()
          Roland Shoemaker . resolved

          I think we should probably just do away with the `depth` argument and move to always using `unmarshalDepth`, since it makes following this all a bit confusing.

          This way we'd remove the depth arg from unmarshal, unmarshalInterface,and unmarshalPath, and add

              unmarshalDepth++
          defer unmarshalDepth--

          to the preamble of each method.

          Ian Alexander

          I think I have a better solution for tracking depth by updating it within the push and pop methods on the decoder.

          File src/encoding/xml/read_test.go
          Line 1162, Patchset 6: depth: maxDepth,
          Roland Shoemaker . resolved

          If we switch to using only unmarshalDepth I believe this would need to be `(maxDepth/4)` and the below would be `(maxDepth/4)+1`, since the DecodeElement loop recurses in unmarshal ~4 times.

          Ian Alexander

          Acknowledged

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Nicholas Husin
          • Roland Shoemaker
          Submit Requirements:
            • requirement is not satisfiedCode-Review
            • requirement satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedReview-Enforcement
            • requirement satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
            Gerrit-Change-Number: 803320
            Gerrit-PatchSet: 10
            Gerrit-Owner: Ian Alexander <ji...@google.com>
            Gerrit-Reviewer: Ian Alexander <ji...@google.com>
            Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
            Gerrit-CC: Roland Shoemaker <rol...@golang.org>
            Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
            Gerrit-Attention: Nicholas Husin <n...@golang.org>
            Gerrit-Comment-Date: Thu, 23 Jul 2026 21:32:19 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: No
            Comment-In-Reply-To: Roland Shoemaker <rol...@golang.org>
            Comment-In-Reply-To: Nicholas Husin <n...@golang.org>
            unsatisfied_requirement
            satisfied_requirement
            open
            diffy

            Nicholas Husin (Gerrit)

            unread,
            Jul 28, 2026, 3:21:10 PM (12 days ago) Jul 28
            to Ian Alexander, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Roland Shoemaker, golang-co...@googlegroups.com
            Attention needed from Ian Alexander and Roland Shoemaker

            Nicholas Husin added 1 comment

            Commit Message
            Line 22, Patchset 10 (Latest):
            Fixes #80481
            Nicholas Husin . unresolved

            Reminder to cherrypick to 1.27 release branch too.

            Open in Gerrit

            Related details

            Attention is currently required from:
            • Ian Alexander
            • Roland Shoemaker
            Submit Requirements:
              • requirement is not satisfiedCode-Review
              • requirement is not satisfiedNo-Unresolved-Comments
              • requirement is not satisfiedReview-Enforcement
              • requirement satisfiedTryBots-Pass
              Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
              Gerrit-MessageType: comment
              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
              Gerrit-Change-Number: 803320
              Gerrit-PatchSet: 10
              Gerrit-Owner: Ian Alexander <ji...@google.com>
              Gerrit-Reviewer: Ian Alexander <ji...@google.com>
              Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
              Gerrit-CC: Roland Shoemaker <rol...@golang.org>
              Gerrit-Attention: Ian Alexander <ji...@google.com>
              Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
              Gerrit-Comment-Date: Tue, 28 Jul 2026 19:21:06 +0000
              Gerrit-HasComments: Yes
              Gerrit-Has-Labels: No
              unsatisfied_requirement
              satisfied_requirement
              open
              diffy

              Roland Shoemaker (Gerrit)

              unread,
              Jul 28, 2026, 3:40:11 PM (12 days ago) Jul 28
              to Ian Alexander, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Nicholas Husin, golang-co...@googlegroups.com
              Attention needed from Ian Alexander

              Roland Shoemaker voted and added 11 comments

              Votes added by Roland Shoemaker

              Code-Review+2

              11 comments

              Patchset-level comments
              File-level comment, Patchset 10 (Latest):
              Roland Shoemaker . resolved

              From my reading this maintains our old behavior while significantly improving the coverage. Since we now essentially increment the depth every time we parse a start element, I think this should be a concrete fix. Thanks!

              Commit Message
              Line 19, Patchset 10 (Latest):interleaving elements with and without custom unmarshalers.
              Roland Shoemaker . unresolved

              Can you include a note about the new behavior, and why we decided on it vs. the old implementation.

              File src/encoding/xml/read.go
              Line 550, Patchset 10 (Latest): // unmarshalPath can call unmarshal, so we need to pass the depth through so that
              Roland Shoemaker . unresolved

              Stale comment.

              Line 751, Patchset 10 (Latest): // the recursion depth of unmarshalPath is limited to the path length specified
              Roland Shoemaker . unresolved

              Stale comment.

              File src/encoding/xml/read_test.go
              Line 1147, Patchset 10 (Latest): builder := os.Getenv("GO_BUILDER_NAME")
              Roland Shoemaker . unresolved

              We should use the same wasm check/bypass in all of the depth tests (new and old) consistently.

              Line 1225, Patchset 10 (Latest): if err == nil {
              Roland Shoemaker . unresolved

              Check we are returning errUnmarshalDepth here and throughout, so we know we are returning the correct error.

              Line 1226, Patchset 10 (Latest): t.Fatal("Unmarshaled 15,003 levels deep without error (depth limit bypassed)")
              Roland Shoemaker . unresolved

              Use the constant, so if it changes the error message doesn't become confusing.

              Line 1253, Patchset 10 (Latest):func TestManual(t *testing.T) {
              Roland Shoemaker . unresolved

              TestRecursiveUnmarshalInterfaceDepth

              Line 1254, Patchset 10 (Latest): depth := 10001
              Roland Shoemaker . unresolved

              maxUnmarshalDepth+1

              Line 1262, Patchset 10 (Latest): if err == nil {
              Roland Shoemaker . unresolved

              Same here, check for errUnmarshalDepth.

              File src/encoding/xml/xml.go
              Line 551, Patchset 10 (Latest): if s := d.stk; s != nil && s.kind == stkStart {
              Roland Shoemaker . unresolved

              I think this breaks our previous behavior. The intention here (if I'm remembering correctly) is to prevent using RawToken from inside of custom UnmarshalXML methods. This change would break streaming Decoders, I believe. Probably we should just add a bool to Decoder that indicates if we're inside of UnmarshalXML and set/unset it appropriately, then check that here.

              Open in Gerrit

              Related details

              Attention is currently required from:
              • Ian Alexander
              Submit Requirements:
              • requirement satisfiedCode-Review
              • requirement is not satisfiedNo-Unresolved-Comments
              • requirement satisfiedReview-Enforcement
              • requirement satisfiedTryBots-Pass
              Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
              Gerrit-MessageType: comment
              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
              Gerrit-Change-Number: 803320
              Gerrit-PatchSet: 10
              Gerrit-Owner: Ian Alexander <ji...@google.com>
              Gerrit-Reviewer: Ian Alexander <ji...@google.com>
              Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
              Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
              Gerrit-Comment-Date: Tue, 28 Jul 2026 19:40:07 +0000
              Gerrit-HasComments: Yes
              Gerrit-Has-Labels: Yes
              satisfied_requirement
              unsatisfied_requirement
              open
              diffy

              Ian Alexander (Gerrit)

              unread,
              Jul 28, 2026, 5:11:42 PM (11 days ago) Jul 28
              to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
              Attention needed from Ian Alexander

              Ian Alexander uploaded new patchset

              Ian Alexander uploaded patch set #11 to this change.
              Following approvals got outdated and were removed:

              Related details

              Attention is currently required from:
              • Ian Alexander
              Submit Requirements:
                • requirement satisfiedCode-Review
                • requirement is not satisfiedNo-Unresolved-Comments
                • requirement satisfiedReview-Enforcement
                • requirement is not satisfiedTryBots-Pass
                Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                Gerrit-MessageType: newpatchset
                Gerrit-Project: go
                Gerrit-Branch: master
                Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
                Gerrit-Change-Number: 803320
                Gerrit-PatchSet: 11
                satisfied_requirement
                unsatisfied_requirement
                open
                diffy

                Ian Alexander (Gerrit)

                unread,
                Jul 28, 2026, 5:44:32 PM (11 days ago) Jul 28
                to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
                Attention needed from Ian Alexander

                Ian Alexander uploaded new patchset

                Ian Alexander uploaded patch set #12 to this change.
                Open in Gerrit

                Related details

                Attention is currently required from:
                • Ian Alexander
                Submit Requirements:
                • requirement satisfiedCode-Review
                • requirement is not satisfiedNo-Unresolved-Comments
                • requirement satisfiedReview-Enforcement
                • requirement is not satisfiedTryBots-Pass
                Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                Gerrit-MessageType: newpatchset
                Gerrit-Project: go
                Gerrit-Branch: master
                Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
                Gerrit-Change-Number: 803320
                Gerrit-PatchSet: 12
                satisfied_requirement
                unsatisfied_requirement
                open
                diffy

                Ian Alexander (Gerrit)

                unread,
                Jul 28, 2026, 6:31:39 PM (11 days ago) Jul 28
                to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
                Attention needed from Ian Alexander

                Ian Alexander uploaded new patchset

                Ian Alexander uploaded patch set #13 to this change.
                Open in Gerrit

                Related details

                Attention is currently required from:
                • Ian Alexander
                Submit Requirements:
                • requirement satisfiedCode-Review
                • requirement is not satisfiedNo-Unresolved-Comments
                • requirement satisfiedReview-Enforcement
                • requirement is not satisfiedTryBots-Pass
                Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                Gerrit-MessageType: newpatchset
                Gerrit-Project: go
                Gerrit-Branch: master
                Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
                Gerrit-Change-Number: 803320
                Gerrit-PatchSet: 13
                satisfied_requirement
                unsatisfied_requirement
                open
                diffy

                Ian Alexander (Gerrit)

                unread,
                Jul 28, 2026, 6:31:57 PM (11 days ago) Jul 28
                to goph...@pubsubhelper.golang.org, Roland Shoemaker, golang...@luci-project-accounts.iam.gserviceaccount.com, Nicholas Husin, golang-co...@googlegroups.com

                Ian Alexander voted and added 10 comments

                Votes added by Ian Alexander

                Commit-Queue+1

                10 comments

                Commit Message
                Line 19, Patchset 10:interleaving elements with and without custom unmarshalers.
                Roland Shoemaker . resolved

                Can you include a note about the new behavior, and why we decided on it vs. the old implementation.

                Ian Alexander

                Done

                File src/encoding/xml/read.go
                Line 550, Patchset 10: // unmarshalPath can call unmarshal, so we need to pass the depth through so that
                Roland Shoemaker . resolved

                Stale comment.

                Ian Alexander

                Done

                Line 751, Patchset 10: // the recursion depth of unmarshalPath is limited to the path length specified
                Roland Shoemaker . resolved

                Stale comment.

                Ian Alexander

                Done

                File src/encoding/xml/read_test.go
                Line 1147, Patchset 10: builder := os.Getenv("GO_BUILDER_NAME")
                Roland Shoemaker . unresolved

                We should use the same wasm check/bypass in all of the depth tests (new and old) consistently.

                Ian Alexander

                The wazero builder cannot create the executable because of its limited stack size. I'd rather have the test run on the remaining wasm builders. I added a comment explaining. WDYT?

                https://logs.chromium.org/logs/golang/buildbucket/cr-buildbucket/8675524124934755201/+/u/step/13/log/2

                Line 1225, Patchset 10: if err == nil {
                Roland Shoemaker . resolved

                Check we are returning errUnmarshalDepth here and throughout, so we know we are returning the correct error.

                Ian Alexander

                Done

                Line 1226, Patchset 10: t.Fatal("Unmarshaled 15,003 levels deep without error (depth limit bypassed)")
                Roland Shoemaker . resolved

                Use the constant, so if it changes the error message doesn't become confusing.

                Ian Alexander

                Done

                Line 1253, Patchset 10:func TestManual(t *testing.T) {
                Roland Shoemaker . resolved

                TestRecursiveUnmarshalInterfaceDepth

                Ian Alexander

                Done

                Line 1254, Patchset 10: depth := 10001
                Roland Shoemaker . resolved

                maxUnmarshalDepth+1

                Ian Alexander

                Done

                Line 1262, Patchset 10: if err == nil {
                Roland Shoemaker . resolved

                Same here, check for errUnmarshalDepth.

                Ian Alexander

                Done

                File src/encoding/xml/xml.go
                Line 551, Patchset 10: if s := d.stk; s != nil && s.kind == stkStart {
                Roland Shoemaker . resolved

                I think this breaks our previous behavior. The intention here (if I'm remembering correctly) is to prevent using RawToken from inside of custom UnmarshalXML methods. This change would break streaming Decoders, I believe. Probably we should just add a bool to Decoder that indicates if we're inside of UnmarshalXML and set/unset it appropriately, then check that here.

                Ian Alexander

                Done

                Open in Gerrit

                Related details

                Attention set is empty
                Submit Requirements:
                • requirement satisfiedCode-Review
                • requirement is not satisfiedNo-Unresolved-Comments
                • requirement satisfiedReview-Enforcement
                • requirement is not satisfiedTryBots-Pass
                Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                Gerrit-MessageType: comment
                Gerrit-Project: go
                Gerrit-Branch: master
                Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
                Gerrit-Change-Number: 803320
                Gerrit-PatchSet: 13
                Gerrit-Owner: Ian Alexander <ji...@google.com>
                Gerrit-Reviewer: Ian Alexander <ji...@google.com>
                Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
                Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
                Gerrit-Comment-Date: Tue, 28 Jul 2026 22:31:53 +0000
                Gerrit-HasComments: Yes
                Gerrit-Has-Labels: Yes
                Comment-In-Reply-To: Roland Shoemaker <rol...@golang.org>
                satisfied_requirement
                unsatisfied_requirement
                open
                diffy

                Ian Alexander (Gerrit)

                unread,
                Jul 28, 2026, 6:48:11 PM (11 days ago) Jul 28
                to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Roland Shoemaker, Nicholas Husin, golang-co...@googlegroups.com
                Attention needed from Roland Shoemaker

                Ian Alexander voted and added 1 comment

                Votes added by Ian Alexander

                Commit-Queue+1

                1 comment

                File src/encoding/xml/read_test.go
                Line 1147, Patchset 10: builder := os.Getenv("GO_BUILDER_NAME")
                Roland Shoemaker . resolved

                We should use the same wasm check/bypass in all of the depth tests (new and old) consistently.

                Ian Alexander

                The wazero builder cannot create the executable because of its limited stack size. I'd rather have the test run on the remaining wasm builders. I added a comment explaining. WDYT?

                https://logs.chromium.org/logs/golang/buildbucket/cr-buildbucket/8675524124934755201/+/u/step/13/log/2

                Ian Alexander

                Done

                Open in Gerrit

                Related details

                Attention is currently required from:
                • Roland Shoemaker
                Submit Requirements:
                  • requirement satisfiedCode-Review
                  • requirement is not satisfiedNo-Unresolved-Comments
                  • requirement satisfiedReview-Enforcement
                  • requirement satisfiedTryBots-Pass
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: comment
                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
                  Gerrit-Change-Number: 803320
                  Gerrit-PatchSet: 13
                  Gerrit-Owner: Ian Alexander <ji...@google.com>
                  Gerrit-Reviewer: Ian Alexander <ji...@google.com>
                  Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
                  Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
                  Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
                  Gerrit-Comment-Date: Tue, 28 Jul 2026 22:48:07 +0000
                  Gerrit-HasComments: Yes
                  Gerrit-Has-Labels: Yes
                  Comment-In-Reply-To: Ian Alexander <ji...@google.com>
                  Comment-In-Reply-To: Roland Shoemaker <rol...@golang.org>
                  satisfied_requirement
                  unsatisfied_requirement
                  open
                  diffy

                  Ian Alexander (Gerrit)

                  unread,
                  Jul 28, 2026, 7:04:44 PM (11 days ago) Jul 28
                  to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
                  Attention needed from Roland Shoemaker

                  Ian Alexander uploaded new patchset

                  Ian Alexander uploaded patch set #14 to this change.
                  Open in Gerrit

                  Related details

                  Attention is currently required from:
                  • Roland Shoemaker
                  Submit Requirements:
                  • requirement satisfiedCode-Review
                  • requirement is not satisfiedNo-Unresolved-Comments
                  • requirement satisfiedReview-Enforcement
                  • requirement satisfiedTryBots-Pass
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: newpatchset
                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
                  Gerrit-Change-Number: 803320
                  Gerrit-PatchSet: 14
                  satisfied_requirement
                  unsatisfied_requirement
                  open
                  diffy

                  Ian Alexander (Gerrit)

                  unread,
                  Jul 29, 2026, 12:32:40 PM (11 days ago) Jul 29
                  to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Roland Shoemaker, Nicholas Husin, golang-co...@googlegroups.com

                  Ian Alexander added 1 comment

                  Commit Message
                  Line 22, Patchset 10:
                  Fixes #80481
                  Nicholas Husin . resolved

                  Reminder to cherrypick to 1.27 release branch too.

                  Ian Alexander

                  Acknowledged

                  Open in Gerrit

                  Related details

                  Attention set is empty
                  Submit Requirements:
                  • requirement satisfiedCode-Review
                  • requirement satisfiedNo-Unresolved-Comments
                  • requirement satisfiedReview-Enforcement
                  • requirement satisfiedTryBots-Pass
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: comment
                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
                  Gerrit-Change-Number: 803320
                  Gerrit-PatchSet: 14
                  Gerrit-Owner: Ian Alexander <ji...@google.com>
                  Gerrit-Reviewer: Ian Alexander <ji...@google.com>
                  Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
                  Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
                  Gerrit-Comment-Date: Wed, 29 Jul 2026 16:32:33 +0000
                  Gerrit-HasComments: Yes
                  Gerrit-Has-Labels: No
                  Comment-In-Reply-To: Nicholas Husin <n...@golang.org>
                  satisfied_requirement
                  open
                  diffy

                  Ian Alexander (Gerrit)

                  unread,
                  Jul 29, 2026, 12:32:50 PM (11 days ago) Jul 29
                  to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, golang...@luci-project-accounts.iam.gserviceaccount.com, Roland Shoemaker, Nicholas Husin, golang-co...@googlegroups.com

                  Ian Alexander submitted the change with unreviewed changes

                  Unreviewed changes

                  10 is the latest approved patch-set.
                  The change was submitted with unreviewed changes in the following files:

                  ```
                  The name of the file: src/encoding/xml/read.go
                  Insertions: 4, Deletions: 4.

                  @@ -207,6 +207,10 @@
                  // Record that decoder must stop at end tag corresponding to start.
                  d.pushEOF()

                  + savedInUnmarshalXML := d.inUnmarshalXML
                  + d.inUnmarshalXML = true
                  + defer func() { d.inUnmarshalXML = savedInUnmarshalXML }()
                  +
                  err := val.UnmarshalXML(d, *start)
                  if err != nil {
                  d.popEOF()
                  @@ -547,8 +551,6 @@
                  case StartElement:
                  consumed := false
                  if sv.IsValid() {
                  - // unmarshalPath can call unmarshal, so we need to pass the depth through so that
                  - // we can continue to enforce the maximum recursion limit.
                  consumed, err = d.unmarshalPath(tinfo, sv, nil, &t)

                  if err != nil {
                  return err
                  @@ -748,8 +750,6 @@
                  }
                  switch t := tok.(type) {
                  case StartElement:
                  - // the recursion depth of unmarshalPath is limited to the path length specified
                  - // by the struct field tag, so we don't increment the depth here.
                  consumed2, err := d.unmarshalPath(tinfo, sv, parents, &t)
                  if err != nil {
                  return true, err
                  ```
                  ```
                  The name of the file: src/encoding/xml/xml.go
                  Insertions: 18, Deletions: 17.

                  @@ -197,22 +197,23 @@
                  // the attribute xmlns="DefaultSpace".
                  DefaultSpace string

                  - r io.ByteReader
                  - t TokenReader
                  - buf bytes.Buffer
                  - saved *bytes.Buffer
                  - stk *stack
                  - stkDepth int
                  - free *stack
                  - needClose bool
                  - toClose Name
                  - nextToken Token
                  - nextByte int
                  - ns map[string]string
                  - err error
                  - line int
                  - linestart int64
                  - offset int64
                  + r io.ByteReader
                  + t TokenReader
                  + buf bytes.Buffer
                  + saved *bytes.Buffer
                  + stk *stack
                  + stkDepth int
                  + free *stack
                  + needClose bool
                  + toClose Name
                  + nextToken Token
                  + nextByte int
                  + ns map[string]string
                  + err error
                  + line int
                  + linestart int64
                  + offset int64
                  + inUnmarshalXML bool
                  }

                  // NewDecoder creates a new XML parser reading from r.
                  @@ -548,7 +549,7 @@
                  // start and end elements match and does not translate
                  // name space prefixes to their corresponding URLs.
                  func (d *Decoder) RawToken() (Token, error) {
                  - if s := d.stk; s != nil && s.kind == stkStart {
                  + if d.inUnmarshalXML {
                  return nil, errRawToken
                  }
                  return d.rawToken()
                  ```
                  ```
                  The name of the file: src/encoding/xml/read_test.go
                  Insertions: 23, Deletions: 6.

                  @@ -1144,6 +1144,8 @@
                  }

                  func TestDecodeElementRecursion(t *testing.T) {
                  + // The wazero builder is unable to build the test binary due to its small
                  + // stack size.

                  builder := os.Getenv("GO_BUILDER_NAME")
                   	if testing.Short() || strings.Contains(builder, "wazero") {
                  t.Skip("test requires significant memory")
                  @@ -1222,8 +1224,8 @@
                  var node standardNode
                  err := Unmarshal(buf.Bytes(), &node)

                  - if err == nil {
                  - t.Fatal("Unmarshaled 15,003 levels deep without error (depth limit bypassed)")
                  + if err != errUnmarshalDepth {
                  + t.Fatalf("Unexpected error: got %q want %q", err, errUnmarshalDepth)
                  }
                  }

                  @@ -1250,8 +1252,8 @@
                  }
                  }

                  -func TestManual(t *testing.T) {
                  - depth := 10001
                  +func TestRecursiveUnmarshalInterfaceDepth(t *testing.T) {
                  + depth := maxUnmarshalDepth + 1

                  payload := bytes.Join([][]byte{
                  bytes.Repeat([]byte("<a>"), depth),
                  bytes.Repeat([]byte("</a>"), depth),
                  @@ -1259,7 +1261,22 @@

                  var node manualNode
                  err := Unmarshal(payload, &node)
                  - if err == nil {
                  - t.Fatalf("Unmarshal depth limit bypassed: unmarshaled %d levels deep without error", depth)
                  + if err != errUnmarshalDepth {
                  + t.Fatalf("Unexpected error: got %q want %q", err, errUnmarshalDepth)
                  + }
                  +}
                  +
                  +type rawTokenNode struct{}
                  +
                  +func (r *rawTokenNode) UnmarshalXML(d *Decoder, start StartElement) error {
                  + _, err := d.RawToken()
                  + return err
                  +}
                  +
                  +func TestUnmarshalXMLRawToken(t *testing.T) {
                  + var node rawTokenNode
                  + err := Unmarshal([]byte("<a></a>"), &node)
                  + if err != errRawToken {
                  + t.Fatalf("UnmarshalXML calling RawToken: got error %v, want %v", err, errRawToken)
                  }
                  }
                  ```

                  Change information

                  Commit message:
                  encoding/xml: fix depth processing in (*Decoder).unmarshal

                  (*Decoder).DecodeElement bypassed recursion depth guard by unilaterally
                  passing the constant 0 to (*Decoder).unmarshal. Previously, unmarshal
                  depth was tracked via a depth parameter passed down the call stack,
                  which manual loops inside custom UnmarshalXML methods could bypass.

                  This change simplifies depth tracking by maintaining a stack depth value
                  that is adjusted as start elements are pushed / popped. This eliminates
                  the need to reason about and synchronize two different values storing
                  the unmarshal depth.

                  Additionally, guarding (*Decoder).RawToken using parser stack state
                  broke streaming decoders reading tokens within open XML elements. This
                  change simplifies the guard by adding an explicit inUnmarshalXML flag.

                  Thanks to Moran Omer (GitHub: moraneus) for reporting this issue.

                  Fixes #80481
                  Fixes CVE-2026-56859
                  Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
                  Reviewed-by: Roland Shoemaker <rol...@golang.org>
                  Files:
                  • M src/encoding/xml/read.go
                  • M src/encoding/xml/read_test.go
                  • M src/encoding/xml/xml.go
                  Change size: M
                  Delta: 3 files changed, 176 insertions(+), 17 deletions(-)
                  Branch: refs/heads/master
                  Submit Requirements:
                  Open in Gerrit
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: merged
                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: I5e89ebe9101b03545520aba5ea99fbf15bdf0395
                  Gerrit-Change-Number: 803320
                  Gerrit-PatchSet: 15
                  open
                  diffy
                  satisfied_requirement
                  Reply all
                  Reply to author
                  Forward
                  0 new messages