mojira.dev
MC-312520

The `mul` integer provider returns a wrong result instead of an error when the product overflows

This also happens in 26.3.

Steps to Reproduce:

  1. Run: /compute default integer {type:"mul",inputs:[769546,494770,48448661]}

Observed Results:
Number provider returned value 4

Expected Results:
Number provider returned invalid value, like /compute default integer {type:"mul",inputs:[2147483647,2]} does. The
real product is 18446744073709551620 (2^64 + 4).

Code analysis:
Product#getIntUnsafe multiplies into a long with value *= ... and only checks the final result with
ContextIntProvider.longToIntSafe. When the long itself overflows, the wrapped value can fall back inside the int range
and pass the check. Using Math.multiplyExact in the loop would fix this.

Comments 0

No comments.

SamuelTheCheesee

(Unassigned)

Confirmed

Platform HC

Normal

Commands

26.3, 26.4 Snapshot 3

Retrieved