Skip to content

validate direction number degree in SobolSequenceGenerator stream parser - #325

Merged
aherbert merged 6 commits into
apache:masterfrom
dxbjavid:sobol-direction-degree-validation
Aug 24, 2026
Merged

validate direction number degree in SobolSequenceGenerator stream parser#325
aherbert merged 6 commits into
apache:masterfrom
dxbjavid:sobol-direction-degree-validation

Conversation

@dxbjavid

@dxbjavid dxbjavid commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

SobolSequenceGenerator.initFromStream reads a per-dimension degree s from the direction-number stream passed to the public SobolSequenceGenerator(int, InputStream) constructor, then allocates new int[s + 1] and writes direction[d][1..s] even though each direction[d] holds only BITS + 1 entries. A line with s > BITS throws a raw ArrayIndexOutOfBoundsException and s < 1 throws NegativeArraySizeException, instead of the MathParseException this parser uses for every other malformed line. Reject out-of-range s before the allocation so bad input maps to MathParseException like the surrounding token parsing.

@aherbert

aherbert commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the bug fix. Can you add a unit test that fails without the patch. Thank you.

@dxbjavid

dxbjavid commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Added testConstructorDegreeTooLarge. It feeds a stream with degree s=60 (BITS is 52), which hits a raw ArrayIndexOutOfBoundsException without the patch and now gives MathParseException.

@dxbjavid

Copy link
Copy Markdown
Contributor Author

Hi @aherbert

Just a friendly follow-up on this PR. I understand everyone is busy, but I wanted to check whether you've had a chance to review it or if there are any remaining concerns I can help address.

Thank you for your time and feedback.

@aherbert

Copy link
Copy Markdown
Contributor

The CI build fails on the new added test:

Error:  Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:testCompile (default-testCompile) on project commons-math4-legacy: Compilation failure
Error:  /home/runner/work/commons-math/commons-math/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/SobolSequenceGeneratorTest.java:[108,13] unreported exception java.io.IOException; must be caught or declared to be thrown

Please fix the test.

@dxbjavid

Copy link
Copy Markdown
Contributor Author

sure i'll do that. Thanks

@dxbjavid

Copy link
Copy Markdown
Contributor Author

Fixed — the test calls the InputStream constructor which throws IOException, so I declared throws Exception on the method like testConstructor2 does. Builds and passes locally now.

@dxbjavid

Copy link
Copy Markdown
Contributor Author

any update?

@dxbjavid

Copy link
Copy Markdown
Contributor Author

Closing this pull request due to inactivity

@dxbjavid dxbjavid closed this Aug 24, 2026
@aherbert aherbert reopened this Aug 24, 2026
@codecov-commenter

codecov-commenter commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.15%. Comparing base (f554608) to head (47b797d).
⚠️ Report is 342 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #325      +/-   ##
============================================
+ Coverage     86.54%   87.15%   +0.60%     
+ Complexity     9787       89    -9698     
============================================
  Files           532      499      -33     
  Lines         35516    33465    -2051     
  Branches       6194     5834     -360     
============================================
- Hits          30738    29167    -1571     
+ Misses         3518     3172     -346     
+ Partials       1260     1126     -134     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aherbert
aherbert merged commit a6109b5 into apache:master Aug 24, 2026
8 of 12 checks 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.

3 participants