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/06/02 15:59:45 UTC
[PR] HemfPlusPath: validate PointCount before array allocation [poi]
jmestwa-coder opened a new pull request, #1103:
URL: https://github.com/apache/poi/pull/1103
## Summary
Validate `PointCount` before allocating path arrays in `EmfPlusPath`.
## Problem
* `PointCount` is read directly from EMF+ input.
* The value is used as the length of both `pathPoints` and `pointTypes` arrays.
* Invalid values can trigger allocation failures before any path data is processed.
## Fix
* Add validation for `PointCount` using `IOUtils.safelyAllocateCheck(...)`.
* Reject negative and oversized values before array allocation.
* Align `EmfPlusPath` with the existing allocation-safety pattern used elsewhere in HEMF parsing.
--
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] HemfPlusPath: validate PointCount before array allocation [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #1103:
URL: https://github.com/apache/poi/pull/1103#discussion_r3342723236
##########
poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java:
##########
@@ -60,6 +61,13 @@ public enum EmfPlusPathPointType {
@SuppressWarnings("unused")
public static class EmfPlusPath implements EmfPlusObjectData, EmfPlusCompressed, EmfPlusRelativePosition {
+ /**
+ * The maximum number of points (and associated point types) we allocate for a single path.
+ * PointCount is an untrusted 32-bit field, so cap it before it is used as an array length -
+ * consistent with e.g. {@code HemfPlusDraw.MAX_OBJECT_SIZE} and {@code HemfDraw.MAX_NUMBER_OF_POLYGONS}.
+ */
+ private static final int MAX_POINTS = 1_000_000;
Review Comment:
make this configurable by adding a static setter, it's ok to default to 1m
--
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] HemfPlusPath: validate PointCount before array allocation [poi]
Posted by "jmestwa-coder (via GitHub)" <gi...@apache.org>.
jmestwa-coder commented on PR #1103:
URL: https://github.com/apache/poi/pull/1103#issuecomment-4623063797
rebase done.
--
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] HemfPlusPath: validate PointCount before array allocation [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #1103:
URL: https://github.com/apache/poi/pull/1103#discussion_r3343565541
##########
poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java:
##########
@@ -60,6 +61,21 @@ public enum EmfPlusPathPointType {
@SuppressWarnings("unused")
public static class EmfPlusPath implements EmfPlusObjectData, EmfPlusCompressed, EmfPlusRelativePosition {
+ /**
+ * The maximum number of points (and associated point types) we allocate for a single path.
+ * PointCount is an untrusted 32-bit field, so cap it before it is used as an array length -
+ * consistent with e.g. {@code HemfPlusDraw.MAX_OBJECT_SIZE} and {@code HemfDraw.MAX_NUMBER_OF_POLYGONS}.
+ */
+ private static final int DEFAULT_MAX_POINTS = 1_000_000;
+ private static int MAX_POINTS = DEFAULT_MAX_POINTS;
+
+ /**
+ * @param maxPoints the maximum number of points allowed for a single path
+ */
Review Comment:
add a getter as that is more normal in Java and we tend to have getters to match the setters
--
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] HemfPlusPath: validate PointCount before array allocation [poi]
Posted by "jmestwa-coder (via GitHub)" <gi...@apache.org>.
jmestwa-coder commented on code in PR #1103:
URL: https://github.com/apache/poi/pull/1103#discussion_r3343045662
##########
poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java:
##########
@@ -60,6 +61,13 @@ public enum EmfPlusPathPointType {
@SuppressWarnings("unused")
public static class EmfPlusPath implements EmfPlusObjectData, EmfPlusCompressed, EmfPlusRelativePosition {
+ /**
+ * The maximum number of points (and associated point types) we allocate for a single path.
+ * PointCount is an untrusted 32-bit field, so cap it before it is used as an array length -
+ * consistent with e.g. {@code HemfPlusDraw.MAX_OBJECT_SIZE} and {@code HemfDraw.MAX_NUMBER_OF_POLYGONS}.
+ */
+ private static final int MAX_POINTS = 1_000_000;
Review Comment:
Updated as suggested.
--
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] HemfPlusPath: validate PointCount before array allocation [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #1103:
URL: https://github.com/apache/poi/pull/1103
--
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] HemfPlusPath: validate PointCount before array allocation [poi]
Posted by "jmestwa-coder (via GitHub)" <gi...@apache.org>.
jmestwa-coder commented on code in PR #1103:
URL: https://github.com/apache/poi/pull/1103#discussion_r3348237378
##########
poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java:
##########
@@ -60,6 +61,21 @@ public enum EmfPlusPathPointType {
@SuppressWarnings("unused")
public static class EmfPlusPath implements EmfPlusObjectData, EmfPlusCompressed, EmfPlusRelativePosition {
+ /**
+ * The maximum number of points (and associated point types) we allocate for a single path.
+ * PointCount is an untrusted 32-bit field, so cap it before it is used as an array length -
+ * consistent with e.g. {@code HemfPlusDraw.MAX_OBJECT_SIZE} and {@code HemfDraw.MAX_NUMBER_OF_POLYGONS}.
+ */
+ private static final int DEFAULT_MAX_POINTS = 1_000_000;
+ private static int MAX_POINTS = DEFAULT_MAX_POINTS;
+
+ /**
+ * @param maxPoints the maximum number of points allowed for a single path
+ */
Review Comment:
Added a matching getter as suggested.
--
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] HemfPlusPath: validate PointCount before array allocation [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #1103:
URL: https://github.com/apache/poi/pull/1103#issuecomment-4615494857
@jmestwa-coder can you rebase this PR, there are merge conflicts
--
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