Skip to content

validate direction number degree in SobolSequenceGenerator stream parser#325

Open
dxbjavid wants to merge 2 commits into
apache:masterfrom
dxbjavid:sobol-direction-degree-validation
Open

validate direction number degree in SobolSequenceGenerator stream parser#325
dxbjavid wants to merge 2 commits into
apache:masterfrom
dxbjavid:sobol-direction-degree-validation

Conversation

@dxbjavid
Copy link
Copy Markdown
Contributor

@dxbjavid dxbjavid commented Jun 3, 2026

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
Copy link
Copy Markdown
Contributor

aherbert commented Jun 3, 2026

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

@dxbjavid
Copy link
Copy Markdown
Contributor Author

dxbjavid commented Jun 3, 2026

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.

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