forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix overflow during binary encoding of Intervals (MaterializeInc#10589)
In Materialize Intervals internally store the number of months in the interval and the number of nanoseconds. The pg_wire binary format for Intervals is 8 bytes for the number of microseconds, followed 4 bytes for the number of days, followed by 4 bytes for the number of months. When converting an Interval to the pg_wire binary encoding, Materialize extracts as many whole days from the nanoseconds as will fit in 4 bytes (an i32 in Rust). During this it checks if the number of days is larger than i32::MAX protecting from overflow. However, it never checked if the number of days is less than i32::MIN making is susceptible to underflow. This commit fixes that issue. Additionally when converting from the pg_wire binary format to our internal Interval representation, we convert the microseconds (which is stored in an i64) to nanoseconds and then convert the result to an i128. If the microseconds are large enough, the conversion to nanoseconds can overflow the i64. This commit first converts the microseconds to an i128 before converting to nanoseconds, to avoid an overflow.
- Loading branch information
Showing
8 changed files
with
105 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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