Repository navigation
fix: validate BigInt input before it reaches Postgres - #665
Open
Indian-boult wants to merge 1 commit into
Open
Indian-boult wants to merge 1 commit into
Indian-boult wants to merge 1 commit into
Conversation
validate_arg_from_type accepted any string or number for BigInt, so a value like "not-an-int", "1.5" or a number outside the int8 range was only rejected by the int8 cast in the generated SQL. Users got the raw Postgres message, and the issue reports a backend abort on an Alpine musl build. BigInt now accepts JSON integers and strings that parse as an i64 after surrounding spaces are trimmed. Anything else returns "Invalid input for BigInt type", the same error the other scalars return. Strings must be decimal digits with an optional sign because Postgres 16 and later also accept 0x10 and 1_000 while 14 and 15 reject them, and the result should not depend on the server version. Fixes supabase#641
This branch has not been deployed
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.
Fixes #641
validate_arg_from_typelet any string or number through forBigInt, so a bad filter, insert, update or function argument value was only caught by theint8cast in the generated SQL. On Postgres 17 from the Debian image that comes back as the raw Postgres message, for exampleinvalid input syntax for type bigint: "not-an-int". The issue reports a backend abort on an Alpine musl build.BigIntnow accepts JSON integers and strings that parse as ani64after surrounding spaces are trimmed. Anything else returnsInvalid input for BigInt type, the same error the other scalars return. Strings are limited to decimal digits with an optional sign because Postgres 16 and later also accept0x10and1_000while 14 and 15 reject them. With the check in Rust every supported version gives the same answer.Strings like
0x10or1_000worked on Postgres 16 and later and are now rejected. Strings with surrounding spaces such as" 1 "keep working, as Postgres reads them on every version. JSON numbers with a fraction or outside theint8range already failed and now fail with the GraphQL error.byPkarguments do not go throughvalidate_arg_from_typefor any type, so a badBigIntthere still reaches the cast. I left that for a separate change.The new cases are in
test/sql/bigint_is_string.sql. The fullinstallcheckpasses on Postgres 17.