You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "jmestwa-coder (via GitHub)" <gi...@apache.org> on 2026/04/28 13:54:35 UTC
[PR] prevent overflow in blip buffer size calculation [poi]
jmestwa-coder opened a new pull request, #1053:
URL: https://github.com/apache/poi/pull/1053
### Summary
This change updates buffer size calculations in HSLF blip processing to avoid potential integer overflow before array allocation.
### What changed
\- Replaced inline size calculations using \`new byte\[...\]\` with:
\- \`long\`-based size computation
\- \`IOUtils.safelyAllocate(...)\` for allocation
\- Applied consistently to:
\- \`Bitmap\`
\- \`EMF\`
\- \`PICT\`
\- \`WMF\`
### Why
In the current implementation, buffer sizes are computed using integer arithmetic:
new byte\[a + b + c\]
If intermediate values exceed Integer.MAX\_VALUE, this can overflow before allocation, leading to incorrect buffer sizes and runtime failures.
Using IOUtils.safelyAllocate ensures:
* size is evaluated using long
* overflow is detected before allocation
* behavior is consistent with existing POI safety patterns
### Scope
* Limited to HSLF blip classes only
* No API changes
* No behavioral changes for valid inputs
### Notes
This follows the same allocation safety approach already used in other parts of POI.
--
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: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] prevent overflow in blip buffer size calculation [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #1053:
URL: https://github.com/apache/poi/pull/1053#discussion_r3154699995
##########
poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/WMF.java:
##########
@@ -90,7 +90,8 @@ protected byte[] formatImageForSlideshow(byte[] data) {
header.setZipSize(compressed.length);
byte[] checksum = getChecksum(data);
- byte[] rawData = new byte[checksum.length * getUIDInstanceCount() + header.getSize() + compressed.length];
+ long size = (long)checksum.length * getUIDInstanceCount() + header.getSize() + compressed.length;
Review Comment:
Move this calculation and the other new calculations in the PR to a shared method that can be tested in your tests. Your tests don't seem to test the code and don't seem to provide any regression protection for the future. I only have my phone with me so I may have missed something but my cursory check of the new code makes me suspicious that this new code is maintainable.
--
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: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] prevent overflow in blip buffer size calculation [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning closed pull request #1053: prevent overflow in blip buffer size calculation
URL: https://github.com/apache/poi/pull/1053
--
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: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] prevent overflow in blip buffer size calculation [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #1053:
URL: https://github.com/apache/poi/pull/1053#issuecomment-4366632507
I went with https://github.com/apache/poi/pull/1054 instead.
--
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: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] prevent overflow in blip buffer size calculation [poi]
Posted by "jmestwa-coder (via GitHub)" <gi...@apache.org>.
jmestwa-coder commented on code in PR #1053:
URL: https://github.com/apache/poi/pull/1053#discussion_r3178285103
##########
poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/WMF.java:
##########
@@ -90,7 +90,8 @@ protected byte[] formatImageForSlideshow(byte[] data) {
header.setZipSize(compressed.length);
byte[] checksum = getChecksum(data);
- byte[] rawData = new byte[checksum.length * getUIDInstanceCount() + header.getSize() + compressed.length];
+ long size = (long)checksum.length * getUIDInstanceCount() + header.getSize() + compressed.length;
Review Comment:
I updated the calculations to use Math.addExact for clearer, overflow-safe logic and kept the change minimal without adding a new helper. I also updated the test to cover the actual calculation path and verify the overflow behaviour.
--
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: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org