Repository navigation
Commit 25eebb6
authored
fix(bigquery-jdbc): bound BigDecimal scale in epoch-decimal timestamp parsing (#15218)
Bug: b/584839496
### The Issue
`BigQueryTemporalUtility.parseEpochDecimalToInstant` and
`BigQueryTemporalUtility.formatTimestampStringFromEpochDecimal` called
`new BigDecimal(epochDecimal).setScale(..., RoundingMode.DOWN)` without
bounding input length or exponent magnitude. Coercing a `STRING` or
`JSON` column containing a large-exponent scientific-notation value
(such as `"1e100000000"`, `"1e2147483648"`, or
`"12345678901234567890e-100000000"`) via `ResultSet.getTimestamp` or
`ResultSet.getObject`, or formatting out-of-range epoch-decimal strings
in `TIMESTAMP(12)` / `RANGE<TIMESTAMP>`, triggered unbounded
`BigInteger.bigTenToThe` expansion, causing uninterruptible CPU stalls
and uncaught `OutOfMemoryError` (or unchecked `DateTimeException` on
17-digit out-of-range epoch seconds).
### The Fix
- Added `BigQueryTemporalUtility.parseScaledEpochDecimal` to reject
strings longer than 128 characters, short-circuit zero (`signum() == 0`)
and sub-unit magnitudes (`integerDigits <= -scale`) to
`BigDecimal.ZERO.setScale(scale)`, and reject integer magnitudes
exceeding 17 digits (`Instant.MIN..Instant.MAX` width, computed in
`long` arithmetic to prevent 32-bit `int` overflow) before calling
`BigDecimal.setScale`.
- Wrapped `LocalDateTime.ofEpochSecond` in
`formatTimestampStringFromEpochDecimal` to catch `DateTimeException` and
rethrow `BigQueryJdbcException`.
- Added unit regression tests in `BigQueryTemporalUtilityTest` covering
extreme positive exponents, extreme sub-unit/zero exponents, and
overlong inputs.1 parent cadc868 commit 25eebb6
2 files changed
Lines changed: 99 additions & 3 deletions
File tree
- java-bigquery-jdbc/src
- main/java/com/google/cloud/bigquery/jdbc
- test/java/com/google/cloud/bigquery/jdbc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
| 237 | + | |
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
279 | 284 | | |
280 | 285 | | |
281 | 286 | | |
282 | 287 | | |
283 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
284 | 306 | | |
285 | 307 | | |
286 | 308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| 42 | + | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
| |||
388 | 391 | | |
389 | 392 | | |
390 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
391 | 465 | | |
392 | 466 | | |
393 | 467 | | |
| |||
0 commit comments