Skip to content

ConsumeBytes: return nil on out-of-bounds read instead of allocating the requested size - #43

Merged
scudette merged 1 commit into
Velocidex:masterfrom
oioio-space:consume-bytes-nil-on-oob
Sep 8, 2026
Merged

ConsumeBytes: return nil on out-of-bounds read instead of allocating the requested size#43
scudette merged 1 commit into
Velocidex:masterfrom
oioio-space:consume-bytes-nil-on-oob

Conversation

@oioio-space

Copy link
Copy Markdown
Contributor

Follow-up to #40 / #41, covering the one item #41 deliberately left out.

ConsumeBytes returned make([]byte, size) on its out-of-bounds path. Since size comes straight from the stream (an argument length, a string length), a malformed record could make the parser allocate an attacker-chosen amount for a read that had already failed. It now returns nil, consistent with the zero value the other Consume* methods return when the buffer is exhausted.

Every call site was checked for nil-safety: results only flow into bytes.NewBuffer/bytes.NewReader (then binary.Read, which returns io.EOF and is already handled as an error), UTF16LEToUTF8 (which returns early on empty input), range, string(...), or plain assignment. No index expressions on a ConsumeBytes result exist in the module.

bounds_test.go gains TestConsumeBytesOutOfBounds: a size beyond the remaining buffer, and a 1 GiB request against an empty buffer, both assert a nil result (i.e. no allocation of the requested size).

go test ./... is unchanged from master apart from the new test (the two dumpevtx exec tests fail identically on master in an environment without that binary).

@CLAassistant

CLAassistant commented Sep 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@oioio-space
oioio-space force-pushed the consume-bytes-nil-on-oob branch from 5506703 to f37794d Compare September 4, 2026 17:05
Comment thread evtx.go
…the requested size

Follow-up to Velocidex#40 / Velocidex#41. The out-of-bounds path returned make([]byte, size)
where size comes straight from the stream, so a malformed record could make
the parser allocate an attacker-chosen amount for a read that had already
failed. Return nil, the zero value the other Consume* methods use; every
call site tolerates a nil slice. Regression test added.
@oioio-space
oioio-space force-pushed the consume-bytes-nil-on-oob branch from f37794d to 736ec51 Compare September 5, 2026 07:23
@scudette
scudette merged commit dad8dd3 into Velocidex:master Sep 8, 2026
5 checks passed
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.

3 participants