resize-bilinear: guard indirection buffer and packed weights size against overflow#10780
Open
destro4evr-rgb wants to merge 1 commit into
Open
Conversation
…inst overflow xnn_reshape_resize_bilinear2d_nhwc_* and xnn_reshape_resize_bilinear2d_nchw_* computed the indirection buffer size and packed-weights size with raw multiplication: sizeof(void*) * (output_height * output_width * 4) (output_height * output_width * 2) << log2_weight_element_size On 32-bit targets (WebAssembly, ARM32) where size_t is 32 bits, the product overflows when output_height * output_width >= 2^28 (e.g. 16384 x 16384), wrapping the allocation size to zero. xnn_indirection_init_resize_bilinear2d_* then writes 4 * output_height * output_width pointer entries into this undersized buffer, producing a heap out-of-bounds write. Replace the raw multiplications with chained xnn_safe_mul calls that return xnn_status_out_of_memory on overflow, matching the pattern used in other reshape paths.
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.
xnn_reshape_resize_bilinear2d_nhwc_*andxnn_reshape_resize_bilinear2d_nchw_*computed the indirection buffer size and packed-weights size with raw multiplication:On 32-bit targets (WebAssembly, ARM32) where
size_tis 32 bits, the product overflows whenoutput_height * output_width >= 2^28(e.g. 16384 × 16384), wrapping the computed size to zero.xnn_reallocate_memorythen returns a zero-size allocation, andxnn_indirection_init_resize_bilinear2d_*subsequently writes4 * output_height * output_widthpointer entries into this undersized buffer — a heap out-of-bounds write.Replace the raw multiplications with chained
xnn_safe_mulcalls that returnxnn_status_out_of_memoryon overflow, matching the pattern used in other reshape paths.