Skip to content

windows: avoid length overflow in NewNTString#281

Closed
bg0d-droid wants to merge 1 commit into
golang:masterfrom
bg0d-droid:fix-newntstring-length
Closed

windows: avoid length overflow in NewNTString#281
bg0d-droid wants to merge 1 commit into
golang:masterfrom
bg0d-droid:fix-newntstring-length

Conversation

@bg0d-droid

@bg0d-droid bg0d-droid commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

NewNTString currently delegates length initialization to RtlInitString, which cannot accurately represent source strings longer than MAXUSHORT-1 bytes. Reject strings that cannot fit in NTString's uint16 length fields and construct the NTString directly, matching NewNTUnicodeString.

This also adds a boundary round-trip test for NTString.

Verification:

  • env GOOS=windows GOARCH=386 CGO_ENABLED=0 GOCACHE=/tmp/gocache GOMODCACHE=/tmp/gomod go test -c -o /tmp/sys-windows-386.test ./windows
  • env GOOS=windows GOARCH=amd64 CGO_ENABLED=0 GOCACHE=/tmp/gocache GOMODCACHE=/tmp/gomod go test -c -o /tmp/sys-windows-amd64.test ./windows
  • env WINEPREFIX=/home/bg0d/Documents/google_bug/copy_sys/golang_sys/sys/.wine-test wine /tmp/sys-windows-386.test -test.run TestRoundtripNTString -test.v

Updates golang/go#80103

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 282bb48) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/sys/+/793120.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

NewNTString initializes an NTString with RtlInitString, which cannot
accurately represent sources longer than MAXUSHORT-1 bytes. Reject strings
that cannot fit in the uint16 length fields and construct the NTString
directly, matching NewNTUnicodeString.

Add a boundary round-trip test for NTString.

Updates golang/go#80103

Change-Id: Id38882a952330305e6c23d0adc86a8bf7920d30e
@bg0d-droid
bg0d-droid force-pushed the fix-newntstring-length branch from 282bb48 to dd8f9a7 Compare June 22, 2026 19:35
@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/793120.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: dd8f9a7) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/sys/+/793120.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@bg0d-droid

Copy link
Copy Markdown
Contributor Author

Closing this GitHub PR to avoid a duplicate GerritBot-imported CL.

The same patch is uploaded directly to Go Gerrit as:
https://go.dev/cl/793100

That CL tracks golang/go#80103.

@bg0d-droid bg0d-droid closed this Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants