pjfanning opened a new pull request, #1289:
URL: https://github.com/apache/poi/pull/1289
`places` was accepted unbounded: `=DEC2HEX(1E10,1E10)` built a 2 GB padding
string through `String.format("%0NX")` and ran out of memory (a denial of
service by formula content), and `=DEC2HEX(255,11)` returned `000000000FF`.
Excel accepts 1–10 places and returns `#NUM!` otherwise, or when the result
needs more characters than `places`.
| Formula | Before | After (Excel) |
|---|---|---|
| `=DEC2HEX(255,1E10)` | `OutOfMemoryError` | `#NUM!` |
| `=DEC2HEX(255,11)` | `000000000FF` | `#NUM!` |
| `=DEC2HEX(255,1)` | `FF` | `#NUM!` |
| `=DEC2HEX(100,0)` | `64` | `#NUM!` |
| `=DEC2BIN(9,8)` | `1001` | `00001001` |
| `=DEC2HEX(-549755813888)` | `FF80000000` | `8000000000` |
| `=DEC2HEX(549755813887,10)` | `FFFFFFFFFF` | `7FFFFFFFFF` |
Fixed on the way, since the rewrite touched the same lines:
- `DEC2BIN` never zero-padded to `places` — two existing tests had the wrong
value marked `TODO: documentation and behavior do not match here!`; they now
assert the documented result.
- Negative numbers were rendered through an `int` cast
(`number.intValue()`), so anything below `Integer.MIN_VALUE` was wrong; both
functions now mask to the 40-bit / 10-bit two's complement Excel documents.
Positive numbers above the int range with `places` had the same cast.
- A non-integer `number` is truncated toward zero over the whole range
(`DEC2HEX(-0.9)` = `0`, `DEC2BIN(511.9)` = `111111111`, `DEC2BIN(512.5)` =
`#NUM!`).
One existing expectation changes: `DEC2HEX(100,0)` was `64` and is now
`#NUM!`, which is what Excel gives for zero places (the `DEC2BIN`
implementation already did this).
`DEC2OCT` is not implemented in POI, so nothing to do there.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]