Repository navigation
fix: crash parsing array with unterminated quoted element - #1860
Open
Keerthana-64 wants to merge 1 commit into
Open
Keerthana-64 wants to merge 1 commit into
Keerthana-64 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
typecast_array_tokenize derives an element's length by subtracting the two surrounding quote characters, so an element that opens a quote but never closes it (a malformed array literal such as '{"}') has only one quote and l goes negative. that negative length is handed to the element typecasters through typecast_cast and used as a copy or allocation size: typecast_LONGINTEGER_cast runs strncpy(buffer, s, (size_t)len) with len == -1, and the float and binary casters pass it to PyUnicode_FromStringAndSize and PyMem_Malloc, so an int, bigint, numeric, float or bytea array column crashes the client with an out-of-bounds access. a well-behaved server never emits this, but a hostile or compromised one can, the same threat model as the recent malformed int64 and bytea fixes. the negative length is the tokenizer's own bug, so reject the unterminated element there with a DataError, the way the scanner already rejects unbalanced braces and other malformed arrays; that keeps the single fix at the root and covers every element type. the added test feeds the malformed literal to the int, bigint, numeric, float and string array casters, each of which segfaulted before the change.