Skip to content

fix: prevent OOB read in C API header validation (#737)#738

Open
BAder82t wants to merge 1 commit intomicrosoft:mainfrom
BAder82t:fix/c-api-oob-header-737
Open

fix: prevent OOB read in C API header validation (#737)#738
BAder82t wants to merge 1 commit intomicrosoft:mainfrom
BAder82t:fix/c-api-oob-header-737

Conversation

@BAder82t
Copy link
Copy Markdown

Summary

Fixes out-of-bounds read in Serialization_IsCompatibleVersion and Serialization_IsValidHeader (native/src/seal/c/serialization.cpp).

Both functions set *result = false when the caller-provided size does not match sizeof(SEALHeader), but they do not return — execution falls through to memcpy(&header, headerptr, sizeof(SEALHeader)). A caller passing e.g. size = 1 with a 1-byte allocation triggers an OOB read of up to sizeof(SEALHeader) bytes across the FFI boundary, producing information disclosure / DoS.

Fix

Return S_OK immediately after flagging the mismatch so the memcpy never executes on an undersized buffer. Preserves the existing contract (function returns S_OK, *result == false).

Testing

  • Existing SerializationTest suite passes (sealtest --gtest_filter=*Serialization*).
  • Full sealtest suite shows no new failures attributable to this diff. One pre-existing macOS-specific ASan finding in RandomGenerator.UniformRandomGeneratorInfoSaveLoad (memset_s use-after-poison in libsystem_c) is unrelated and reproducible on unpatched main.
  • No C API test harness exists in native/tests/; this change is a strict tightening of an error path.

Closes

#737

Serialization_IsCompatibleVersion and Serialization_IsValidHeader
set *result = false on a caller-buffer size mismatch but fall through
to memcpy(sizeof(SEALHeader)). A caller passing a smaller allocation
(e.g. size=1) triggers an out-of-bounds read of up to
sizeof(SEALHeader) bytes across the FFI boundary, yielding information
disclosure or DoS.

Return S_OK immediately after flagging the mismatch so the memcpy
never runs on an undersized buffer.

Closes microsoft#737
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.

1 participant