Add runtime bounds checks in BufferSerializerIOv2_ReadBuffer
fix(serializer): add runtime bounds checks in BufferSerializerIOv2_ReadBuffer (#1972)
Add runtime bounds checks in BufferSerializerIOv2_ReadBuffer55d986-fix-add-runtime-bounds-checks-in-bufferserializeriov2-cve-2026-7826fixadd runtime bounds checks bufferserializeriov2 readbuffer
Committed by gkorland
commit message
fix(serializer): add runtime bounds checks in BufferSerializerIOv2_ReadBuffer (#1972)
* fix(serializer): add runtime bounds checks in BufferSerializerIOv2_ReadBuffer
BufferSerializerIOv2_ReadBuffer relied solely on ASSERT macros for bounds
validation, which are compiled out in release builds. This left no runtime
protection against malformed or corrupted RDB buffer data.
Add explicit runtime checks for:
- Type field read: verify at least 1 byte remains before reading the
serializer type marker
- Type validation: reject unexpected type values (only blob_t and char*
are valid) instead of falling through to the char* path
- Blob invariant: verify the blob marker appears only at the end of a
buffer, as the write side guarantees
- Length field read: verify sizeof(size_t) bytes remain before reading
the sub-buffer length
- Sub-buffer copy: verify the declared length does not exceed remaining
bytes before memcpy
On validation failure, log a descriptive warning and abort via
RedisModule_Assert(false) to prevent heap out-of-bounds reads from
corrupted data.
Also replace the direct pointer-cast read of the length field with
memcpy to avoid potential unaligned memory access.
Co-authored-by: Copilot <[email protected]>
* mostly formatting
---------
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Roi Lipman <[email protected]>
Co-authored-by: Roi Lipman <[email protected]>Editor assessment
This commit patches CVE-2026-7826. Detailed and well reasoned. The body enumerates every bounds check added - type byte, type value, blob invariant, length field and sub-buffer copy - and explains that ASSERT macros vanish in release builds, so runtime checks were absent. It also mentions replacing the unaligned pointer read with memcpy. Clear and scoped; a sentence on the practical impact of the OOB read would make it a 5. Formally clean and scoped; the body is thorough and separated, and only the practical impact of the OOB read is absent.