Skip to content

Clamp hstore text parser pair-count estimate - #2643

Open
AshSgDe29071999 wants to merge 1 commit into
jackc:masterfrom
AshSgDe29071999:fix/hstore-pairs-estimate-clamp
Open

Clamp hstore text parser pair-count estimate#2643
AshSgDe29071999 wants to merge 1 commit into
jackc:masterfrom
AshSgDe29071999:fix/hstore-pairs-estimate-clamp

Conversation

@AshSgDe29071999

Copy link
Copy Markdown

Fixes #2639

parseHstore sized both the value-string slice and the result map from strings.Count(s, ">") before any pair was parsed. A value consisting only of > reserved memory proportional to its length and then failed on the first consumeExpectedByte('"').

That path is reachable from wire data (scanPlanTextAnyToHstoreScannerparseHstore). Capacity is only a hint to append and make(map), so clamping the estimate cannot change which inputs are accepted or what a successful parse returns.

The garbage-input test covers the unvalidated count. The 2000-pair test checks that a legitimate hstore larger than the clamp still parses completely.

parseHstore sized the result map from the number of '>' bytes in untrusted
input before any pair was validated. A value of only '>' reserved memory
proportional to its length and then failed immediately.

Capacity is only a hint, so clamping cannot change accepted inputs.

See jackc#2639
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant