Conversation
jas_matrix_bindsub used the caller-supplied row/column indices to index mat1->rows_ with no bounds checking, so an out-of-range index read past the rows_ pointer array (heap OOB read). The read pointer was then stored into mat0->rows_ and would be dereferenced by any later accessor. The public inline wrappers jas_matrix_bindrow and jas_matrix_bindcol forward caller indices directly, and unlike the sibling jas_seq2d_bindsub no validation happened on this path. Reject out-of-range or inverted ranges, and a mat1 without a row array, before mat0 is modified. Validation now happens first so a failed bind no longer frees mat0's data. Fixes jasper-software#419.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #419 —
jas_matrix_bindsubindexesmat1->rows_with caller-suppliedr0/r1/c0/c1and no bounds check:The public inline wrappers
jas_matrix_bindrow/jas_matrix_bindcolforward caller indices directly, so any application using them can hit a heap out-of-bounds read. The stored invalid row pointer is dereferenced by later accessors. The siblingjas_seq2d_bindsubdoes validate its range before forwarding — this path did not.Fix
Reject
r0 < 0 || c0 < 0 || r0 > r1 || c0 > c1 || r1 >= mat1->numrows_ || c1 >= mat1->numcols_ || !mat1->rows_beforemat0is modified — so a failed bind no longer freesmat0's data either (the old code destroyedmat0before validating nothing at all).Testing
Reproducer (public API, no file needed):
ERROR: AddressSanitizer: READ of size 8injas_matrix_bindsub(jas_seq.c:242), reached viajas_matrix_bindrow(jas_seq.h:318)jas_matrix_bindrowreturns -1, no sanitizer report