Skip to content

replace casts long to int with Math.toIntExact#1072

Merged
pjfanning merged 6 commits into
apache:trunkfrom
pjfanning:copilot/update-cast-long-to-int
May 14, 2026
Merged

replace casts long to int with Math.toIntExact#1072
pjfanning merged 6 commits into
apache:trunkfrom
pjfanning:copilot/update-cast-long-to-int

Conversation

@pjfanning
Copy link
Copy Markdown
Member

@pjfanning pjfanning commented May 13, 2026

better to throw exception than to risk continuing with an int that overflows

@pjfanning pjfanning marked this pull request as draft May 13, 2026 20:18
@pjfanning pjfanning mentioned this pull request May 13, 2026
@pjfanning pjfanning force-pushed the copilot/update-cast-long-to-int branch from 38d732b to 8daddeb Compare May 13, 2026 22:33
@pjfanning pjfanning mentioned this pull request May 13, 2026
Copilot AI and others added 4 commits May 14, 2026 00:14
Replace explicit (int) casts of long values with Math.toIntExact() to
detect integer overflow at runtime rather than silently truncating.

Changes cover:
- hemf emf records: HemfComment, HemfFill, HemfPalette, HemfDraw, HemfFont
- hpsf: Section, Array, Vector, Property, PropertySet, PropertySetFactory, VariantSupport
- poifs/crypt: CryptoAPIDecryptor, ChunkedCipherOutputStream, XORDecryptor, XOREncryptor
- poi-ooxml XSSF: XSSFConditionalFormattingRule, XSSFDxfStyleProvider, XSSFOptimiser,
  XSSFChildAnchor, XSSFFontFormatting, XSSFDataBarFormatting, XSSFColor, XSSFTableStyle,
  XSSFWorkbook, XSSFSimpleShape, XSSFName, ColumnHelper
- poi-ooxml XSLF: XSLFSimpleShape, XSLFSheet, XSLFTabStop, XSLFDrawing
- poi-ooxml XDDF: XDDFDataSourcesFactory
- hwpf: PlfLfo, RecordUtil
- util: IOUtils
- poifs/nio: ByteArrayBackedDataSource

Guarded casts (already behind Integer.MAX_VALUE checks) and casts of
floating-point or char values are intentionally left unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
…alette/brush indices, fix PropertySetFactory for large sectionCount

Agent-Logs-Url: https://github.com/pjfanning/poi/sessions/1fcc029e-f25e-4e46-be29-fc0831ec0ee1

Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
…tySetFactory, keep (Long) cast in XSSFChildAnchor

Agent-Logs-Url: https://github.com/pjfanning/poi/sessions/1fcc029e-f25e-4e46-be29-fc0831ec0ee1

Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
@pjfanning pjfanning force-pushed the copilot/update-cast-long-to-int branch from 8daddeb to 2c952bb Compare May 13, 2026 23:24
@pjfanning pjfanning marked this pull request as ready for review May 14, 2026 10:25
@pjfanning pjfanning merged commit 9727f3e into apache:trunk May 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants