Skip to content

avoid out-of-bounds write in deserializer_t::pop_array#5644

Open
Keerthana-64 wants to merge 1 commit into
uxlfoundation:mainfrom
Keerthana-64:pop-array-capacity-bound
Open

avoid out-of-bounds write in deserializer_t::pop_array#5644
Keerthana-64 wants to merge 1 commit into
uxlfoundation:mainfrom
Keerthana-64:pop-array-capacity-bound

Conversation

@Keerthana-64

Copy link
Copy Markdown

Description

ASan, deserializing a crafted quantization entry into group_dims_:

==ERROR: AddressSanitizer: stack-buffer-overflow
WRITE of size 800
    #1 serialization_stream_t::get(...)              serialization.hpp:150
    #2 deserializer_t::pop_array<long long>(size_t&, long long*) serialization.hpp:276
  ... [192, 288) 'group_dims'  <== 96-byte buffer, 800-byte write

quant_entry_t::deserialize reads group_ndims from the byte stream and hands it to deserializer_t::pop_array, which copies sizeof(dim_t) * group_ndims into the fixed group_dims_ (a dims_t, DNNL_MAX_NDIMS entries). Nothing bounds the count, so a serialized entry whose group_ndims exceeds DNNL_MAX_NDIMS writes past the array with stream-supplied bytes. The bound belongs in the deserializer rather than the caller, so pop_array now takes the destination capacity and drops counts larger than it; the quant deserializer passes DNNL_MAX_NDIMS. Entries whose count fits the destination round-trip unchanged.

Reproduce: build a stream of group_ndims = 100 followed by 100 int64 values and deserialize it into the 12-entry group_dims_. Before the change ASan reports the write above (704 bytes past the buffer); after it, the count is refused and the destination is left untouched. The new gtest in tests/gtests/internals/test_serialization.cpp covers both the oversized-count rejection and a valid round-trip.

Checklist

General

  • Do all unit and benchdnn tests (make test and make test_benchdnn_*) pass locally for each commit?
  • Have you formatted the code using clang-format?

Bug fixes

  • Have you included information on how to reproduce the issue (either in a github issue or in this PR)?
  • Have you added relevant regression tests?

@Keerthana-64
Keerthana-64 requested a review from a team as a code owner July 21, 2026 09:37
@github-actions github-actions Bot added component:tests Codeowner: @oneapi-src/onednn-arch component:common labels Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:common component:tests Codeowner: @oneapi-src/onednn-arch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant