Skip to content

language: limit TextUnmarshaler tag complexity - #68

Open
carrerasdarren-cell wants to merge 1 commit into
golang:masterfrom
carrerasdarren-cell:language-unmarshal-complexity
Open

language: limit TextUnmarshaler tag complexity#68
carrerasdarren-cell wants to merge 1 commit into
golang:masterfrom
carrerasdarren-cell:language-unmarshal-complexity

Conversation

@carrerasdarren-cell

Copy link
Copy Markdown

The BCP 47 tag parser has inherent quadratic time complexity.
ParseAcceptLanguage bounds that work, but Tag.UnmarshalText still passes
untrusted JSON, XML, and direct text input to the parser without a
complexity limit.

Reject inputs with more than 1000 total dash and underscore separators
before parsing. Count both spellings because the scanner accepts each as
a tag separator. Add regression coverage for both forms.

A 320 kB reproduction with 32,000 invalid subtags dropped from 71-77 ms
to under 1 ms. The complete x/text test suite, focused race tests, and
go vet pass.

Fixes golang/go#80160.

The BCP 47 parser has inherent quadratic time complexity. Tag.UnmarshalText
still passed JSON, XML, and direct text input to it without the limit
already used by ParseAcceptLanguage.

Reject inputs with more than 1000 total dash and underscore separators
before parsing. Count both spellings because the scanner accepts both as
tag separators, and add regression coverage for each form.

Fixes golang/go#80160.
@gopherbot

Copy link
Copy Markdown
Contributor

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

Please visit Gerrit at https://go-review.googlesource.com/c/text/+/805000.

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.

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.

x/text/language: Tag missing TextUnmarshaler quadratic parse protections

2 participants