prisma / tiberius

TDS 7.2+ (Microsoft SQL Server) driver for Rust
Apache License 2.0
321 stars 118 forks source link

fix: bigdecimal conversion overflow #271

Closed Weakky closed 1 year ago

Weakky commented 1 year ago

Overview

Discovered while working on https://github.com/prisma/client-planning/issues/237

10i64.pow(u32::try_from(exp.abs()) overflowed for large numbers. The public BigDecimal API splits the computation and performs the power on a BigInt to avoid this overflow.

https://github.com/akubera/bigdecimal-rs/blob/master/src/lib.rs#L76-L94

Let me know if you think it's better to own this code. There's no public issue because this was discovered while working on JSON protocol which lifted some GQL int boundary limitation and made it possible to cross this code path. Specifically, it made this test fail.