Repository navigation
fix(bigquery-jdbc): bound BigDecimal scale in epoch-decimal timestamp parsing - #15218
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces safe parsing of epoch decimal strings in BigQueryTemporalUtility to prevent potential performance issues or Denial of Service (DoS) vulnerabilities caused by extremely large or long decimal values. It adds a helper method parseScaledEpochDecimal that enforces length limits, validates the number of integer digits, and handles extreme sub-unit exponents efficiently. Additionally, it wraps LocalDateTime.ofEpochSecond in a try-catch block to handle DateTimeException gracefully. Corresponding unit tests have been added to verify these edge cases. I have no feedback to provide as there are no review comments.
logachev
approved these changes
Nov 25, 2026
logachev
reviewed
Nov 25, 2026
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.
Bug: b/584839496
The Issue
BigQueryTemporalUtility.parseEpochDecimalToInstantandBigQueryTemporalUtility.formatTimestampStringFromEpochDecimalcallednew BigDecimal(epochDecimal).setScale(..., RoundingMode.DOWN)without bounding input length or exponent magnitude. Coercing aSTRINGorJSONcolumn containing a large-exponent scientific-notation value (such as"1e100000000","1e2147483648", or"12345678901234567890e-100000000") viaResultSet.getTimestamporResultSet.getObject, or formatting out-of-range epoch-decimal strings inTIMESTAMP(12)/RANGE<TIMESTAMP>, triggered unboundedBigInteger.bigTenToTheexpansion, causing uninterruptible CPU stalls and uncaughtOutOfMemoryError(or uncheckedDateTimeExceptionon 17-digit out-of-range epoch seconds).The Fix
BigQueryTemporalUtility.parseScaledEpochDecimalto reject strings longer than 128 characters, short-circuit zero (signum() == 0) and sub-unit magnitudes (integerDigits <= -scale) toBigDecimal.ZERO.setScale(scale), and reject integer magnitudes exceeding 17 digits (Instant.MIN..Instant.MAXwidth, computed inlongarithmetic to prevent 32-bitintoverflow) before callingBigDecimal.setScale.LocalDateTime.ofEpochSecondinformatTimestampStringFromEpochDecimalto catchDateTimeExceptionand rethrowBigQueryJdbcException.BigQueryTemporalUtilityTestcovering extreme positive exponents, extreme sub-unit/zero exponents, and overlong inputs.