Repository navigation
fix: signed overflow parsing malformed date and time input - #1862
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
typecast_parse_date() and typecast_parse_time() accumulated each field in an int without overflow check, and the time zone offset was computed in int too. A field with too many digits overflowed and could silently wrap to a valid value: '4294969296-01-01' was parsed as 2000-01-01. Reject such fields instead, as the interval parser already does.
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_parse_date()/typecast_parse_time()from master, built standalone with clang and run on two malformed values:Each field is accumulated in an int with no bound, and the offset
3600 * tzhh + 60 * tzmm + tzssis computed in int too. So a malformed value wraps into a valid one and is returned silently:DATE('4294969296-01-01')givesdate(2000, 1, 1)and the timestamp/time offset becomes +01:00, instead of raising. As with the recent bytea and int64 fixes, getting such a value into the client needs a malicious server. The interval parser already raises in this case (test_interval_overflow: "I want an error, not a random number").The parsers now return a parse error once a field reaches 10 digits (no valid field gets close), so callers raise
DataError. The offset is computed inPY_LONG_LONGand rejected if it doesn't fit an int. Valid input is unaffected: the same harness gives identical results before and after for the values intest_dates.pyplus extremes (294276-12-31,+15:59:59,24:00:00), and the trap build no longer fires. I couldn't runmake checkhere (no libpq/PostgreSQL on this machine), so the newtest_parse_overflowstill needs a CI run.