Repository navigation
Validate livewire indices and reject images too large for int indexing - #32
Open
argusSecurityBot wants to merge 2 commits into
Open
argusSecurityBot wants to merge 2 commits into
argusSecurityBot wants to merge 2 commits into
Conversation
LiveWire.select only checked tuple/list coordinates; an integer index was passed to the C extension unchecked and used to index the cost, predecessor and label arrays. Reject indices outside the image, keeping -1 as a no-op while no source is set, which close() relies on. The grid routines compute the number of pixels as an int product of the image dimensions, so images with more than INT_MAX elements wrap the size and under-allocate the heap that is then indexed with the real pixel coordinates. Raise ValueError for such inputs instead.
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.
LiveWire.select()bounds-checks only a(y, x)tuple (src/pyift/livewire.py:166); a plain int index goes unchecked to_pyift.livewire_pathassrc/dst(livewire.py:192)._livewirePaththen writescosts_ptr[src]/preds_ptr[src]/labels_ptr[src](_livewire.c:63) and readspreds_ptr[dst](_livewire.c:150), so an index outside the image is an out-of-bounds write or read.Separately, the grid routines compute the pixel count as
int size = shape.x * shape.y * shape.z(_shortestpath.c:48, same pattern at 290, 457, 629, 775, 918, 1063); above INT_MAX it wraps,createHeap(size)(line 65) under-allocates, and the loop indexes it with real pixel indices (line 93).Fix:
select()raisesValueErrorfor an int index outside[0, height*width)(-1 stays a no-op with no source set), and each routine raisesValueErrorwhen the array has more than INT_MAX elements.SUMMARY: AddressSanitizer: heap-buffer-overflow _livewire.c:63(WRITE). Tests: 12 passed before and after.