Skip to content

reftable: bound an object record's offset count by its length - #7423

Open
msuozzo wants to merge 1 commit into
libgit2:mainfrom
msuozzo:push-pqrqlltwmruy
Open

msuozzo wants to merge 1 commit into
libgit2:mainfrom
msuozzo:push-pqrqlltwmruy

Conversation

@msuozzo

@msuozzo msuozzo commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

An object record's count of offsets is a 64-bit varint from the table,
and reftable_obj_record_decode allocated the offsets array from it
through REFTABLE_ALLOC_ARRAY, which takes a size_t. Where size_t is 32
bits, a count of 2^32 + 1 allocates room for one offset, and the loop,
which runs to the full count, writes an offset from the table for each
varint left in the block past the end of the array. Where size_t is 64
bits, a large count only makes a large allocation that the decode then
fails to fill, so this is a real problem only on 32-bit builds.

Nothing in libgit2 reaches this decoder: a block of a type other than
the one wanted is refused before its records are decoded, and the
object index, the only reader of object blocks, is not used. The
decoder is still wrong.

Each offset takes at least a byte, so refuse a count larger than what
is left of the record.

An object record's count of offsets is a 64-bit varint from the table,
and reftable_obj_record_decode allocated the offsets array from it
through REFTABLE_ALLOC_ARRAY, which takes a size_t. Where size_t is 32
bits, a count of 2^32 + 1 allocates room for one offset, and the loop,
which runs to the full count, writes an offset from the table for each
varint left in the block past the end of the array. Where size_t is 64
bits, a large count only makes a large allocation that the decode then
fails to fill, so this is a real problem only on 32-bit builds.

Nothing in libgit2 reaches this decoder: a block of a type other than
the one wanted is refused before its records are decoded, and the
object index, the only reader of object blocks, is not used. The
decoder is still wrong.

Each offset takes at least a byte, so refuse a count larger than what
is left of the record.
@ethomson

Copy link
Copy Markdown
Member

We take the reftable dependency directly from git. I'd ask you to take this update to them first and then we'll include it. 🙏

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants