Skip to main content
Menu
Advisories

pgjdbc stores a different number for a BigDecimal outside the binary numeric range

GHSA-CJCW-9R77-4GWMPublished Updated GitHub

Description

pgjdbc cut the weight and scale of a BigDecimal to 16 bits when it sent the value in binary. The server then stored a different number without an error.

Details

The binary numeric format holds a 16-bit weight and a 14-bit scale. The driver did not check either. 999999.99e-262144 was stored as 999999.99, and 1e131072 as 0.

The driver also computed 10 to the power of the scale before it sent anything. A value such as 1e-200000000 kept a thread busy for minutes.

Binary transfer is on by default, so setBigDecimal() and setObject() used this path.

Proof of concept

PreparedStatement ps = conn.prepareStatement("SELECT ?::numeric");
ps.setBigDecimal(1, new BigDecimal("999999.99e-262144"));
ps.executeQuery(); // Returns 999999.99 instead of a numeric overflow error.

Impact

An attacker who supplies a decimal number that the application parses can make it store a different number. A tiny value can pass a range check and be stored as a large one. A short input can also use minutes of CPU per request.

Affected versions

References

GitHub · pgjdbc/pgjdbc