Skip to content

Operators for BigDecimal (+, -, %, /%, quot, etc.) don't use value of mc (MathContext) #10882

Closed
scala/scala
#6884
@plokhotnyuk

Description

@plokhotnyuk

It can lead for security problems in open systems, which use these operators without checking of scale of received BigDecimal values.

Following code can grab CPU core for several minutes and then will throw an out of memory error:

BigDecimal("1e1000000000", java.math.MathContext.DECIMAL128) + 1

W/A is using of methods of underlying java.math.BigDecimal, like:

BigDecimal("1e1000000000").underlying.add(BigDecimal("1").underlying, java.math.MathContext.DECIMAL128)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions