[net] dict: fix unquote panic when backslash is the last character

2 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Aug 9, 2026, 2:31:32 AM (yesterday) Aug 9
to goph...@pubsubhelper.golang.org, 张世杰, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

dict: fix unquote panic when backslash is the last character

The unquote function did not check bounds after advancing past a backslash, causing an index out of range panic when the backslash was the final character in the string.

Add a bounds check and break out of the loop when the backslash has no following character to escape.

This PR will be imported into Gerrit with the title and first
comment (this text) used to generate the subject and body of
the Gerrit change.

**Please ensure you adhere to every item in this list.**

More info can be found at https://go.dev/wiki/CommitMessage

+ The PR title is formatted as follows: `net/http: frob the quux before blarfing`
+ The package name goes before the colon
+ The part after the colon uses the verb tense + phrase that completes the blank in,
"This change modifies Go to ___________"
+ Lowercase verb after the colon
+ No trailing period
+ Keep the title as short as possible, ideally 72 characters or shorter
+ No Markdown
+ The first PR comment (this one) is wrapped at around 72 characters, unless it's
really needed (ASCII art, table, or long link)
+ If there is a corresponding issue,
add either `Fixes golang/go#1234` or `Updates golang/go#1234`
(the latter if this is not a complete fix) to this comment
+ Most Go repositories use the main issue tracker in the `golang/go` repo.
If this PR is for a repository with a dedicated issue tracker,
use the `owner/repo#issue_number` syntax: `Fixes golang/vscode-go#1234`
+ We do not use Signed-off-by lines in Go. Please don't add them.
Our Gerrit server & GitHub bots enforce CLA compliance instead.
+ Delete these instructions once you have read and applied them
Change-Id: I016a0aa808ce9084fb869c42aaadbf115e7321c2
GitHub-Last-Rev: 2c6d3f16337e9a8987db5ff86787ca8567b95e32
GitHub-Pull-Request: golang/net#259

Change diff

diff --git a/dict/dict.go b/dict/dict.go
index da1f072..b3e9a84 100644
--- a/dict/dict.go
+++ b/dict/dict.go
@@ -203,6 +203,9 @@
c := b[r]
if c == '\\' {
r++
+ if r >= len(b) {
+ break
+ }
c = b[r]
}
b[w] = c
diff --git a/dict/dict_test.go b/dict/dict_test.go
new file mode 100644
index 0000000..68b29e7
--- /dev/null
+++ b/dict/dict_test.go
@@ -0,0 +1,28 @@
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package dict
+
+import "testing"
+
+func TestUnquote(t *testing.T) {
+ tests := []struct {
+ in, want string
+ }{
+ {"hello", "hello"},
+ {`hello\ world`, "hello world"},
+ {`hello\\world`, `hello\world`},
+ {`trailing\\`, `trailing\`},
+ {`\\`, `\`},
+ {`\`, ""},
+ {`a\`, "a"},
+ {`\a`, "a"},
+ }
+ for _, tt := range tests {
+ got := unquote(tt.in)
+ if got != tt.want {
+ t.Errorf("unquote(%q) = %q, want %q", tt.in, got, tt.want)
+ }
+ }
+}

Change information

Files:
  • M dict/dict.go
  • A dict/dict_test.go
Change size: S
Delta: 2 files changed, 31 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
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: newchange
Gerrit-Project: net
Gerrit-Branch: master
Gerrit-Change-Id: I016a0aa808ce9084fb869c42aaadbf115e7321c2
Gerrit-Change-Number: 812301
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: 张世杰 <zsj...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
Aug 9, 2026, 2:31:35 AM (yesterday) Aug 9
to 张世杰, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems with your PR:

  1. Do you still have the GitHub PR instructions in your commit message text? The PR instructions should be deleted once you have applied them.
2. Do you have the right bug reference format? For the net repo, the format is usually 'Fixes golang/go#12345' or 'Updates golang/go#12345' at the end of the commit message.

Please address any problems by updating the GitHub PR.

When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

For more details, see:

(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

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: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I016a0aa808ce9084fb869c42aaadbf115e7321c2
    Gerrit-Change-Number: 812301
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: 张世杰 <zsj...@gmail.com>
    Gerrit-Comment-Date: Sun, 09 Aug 2026 06:31:29 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Aug 9, 2026, 2:34:28 AM (yesterday) Aug 9
    to 张世杰, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Message from Gopher Robot

    Congratulations on opening your first change. Thank you for your contribution!

    Next steps:
    A maintainer will review your change and provide feedback. See
    https://go.dev/doc/contribute#review for more info and tips to get your
    patch through code review.

    Most changes in the Go project go through a few rounds of revision. This can be
    surprising to people new to the project. The careful, iterative review process
    is our way of helping mentor contributors and ensuring that their contributions
    have a lasting impact.

    During May-July and Nov-Jan the Go project is in a code freeze, during which
    little code gets reviewed or merged. If a reviewer responds with a comment like
    R=go1.11 or adds a tag like "wait-release", it means that this CL will be
    reviewed as part of the next development cycle. See https://go.dev/s/release
    for more details.

    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: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I016a0aa808ce9084fb869c42aaadbf115e7321c2
    Gerrit-Change-Number: 812301
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: 张世杰 <zsj...@gmail.com>
    Gerrit-Comment-Date: Sun, 09 Aug 2026 06:34:24 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Gerrit Bot (Gerrit)

    unread,
    Aug 9, 2026, 2:48:25 AM (yesterday) Aug 9
    to 张世杰, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #2 to this change.
    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: newpatchset
    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I016a0aa808ce9084fb869c42aaadbf115e7321c2
    Gerrit-Change-Number: 812301
    Gerrit-PatchSet: 2
    unsatisfied_requirement
    open
    diffy

    张世杰 (Gerrit)

    unread,
    1:53 AM (4 hours ago) 1:53 AM
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Damien Neil, Ian Lance Taylor, Nicholas Husin, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Damien Neil, Ian Lance Taylor and Nicholas Husin

    张世杰 added 2 comments

    Patchset-level comments
    File-level comment, Patchset 1:
    Gopher Robot . resolved

    I spotted some possible problems with your PR:

      1. Do you still have the GitHub PR instructions in your commit message text? The PR instructions should be deleted once you have applied them.
    2. Do you have the right bug reference format? For the net repo, the format is usually 'Fixes golang/go#12345' or 'Updates golang/go#12345' at the end of the commit message.

    Please address any problems by updating the GitHub PR.

    When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

    To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

    For more details, see:

    (In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

    张世杰

    Done

    File-level comment, Patchset 2 (Latest):
    张世杰 . resolved

    Removed the template instructions from the PR description.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Damien Neil
    • Ian Lance Taylor
    • 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: net
      Gerrit-Branch: master
      Gerrit-Change-Id: I016a0aa808ce9084fb869c42aaadbf115e7321c2
      Gerrit-Change-Number: 812301
      Gerrit-PatchSet: 2
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: 张世杰 <zsj...@gmail.com>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Attention: Damien Neil <dn...@google.com>
      Gerrit-Attention: Nicholas Husin <n...@golang.org>
      Gerrit-Comment-Date: Mon, 10 Aug 2026 05:53:10 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Gopher Robot <go...@golang.org>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      1:54 AM (4 hours ago) 1:54 AM
      to 张世杰, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Damien Neil, Ian Lance Taylor and Nicholas Husin

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #3 to this change.
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Damien Neil
      • Ian Lance Taylor
      • 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: net
      Gerrit-Branch: master
      Gerrit-Change-Id: I016a0aa808ce9084fb869c42aaadbf115e7321c2
      Gerrit-Change-Number: 812301
      Gerrit-PatchSet: 3
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages