Skip to content

fix: prevent silent overflow in calloc#370

Merged
apoelstra merged 1 commit into
BlockstreamResearch:masterfrom
stringhandler:fix/silent-overflow-calloc
Jun 22, 2026
Merged

fix: prevent silent overflow in calloc#370
apoelstra merged 1 commit into
BlockstreamResearch:masterfrom
stringhandler:fix/silent-overflow-calloc

Conversation

@stringhandler

Copy link
Copy Markdown
Contributor

Minor overflow prevention.

Overflow can silently occur in release builds. Low priority but simple enough fix.

@delta1 delta1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 11153bb; tested locally

@apoelstra

Copy link
Copy Markdown
Collaborator

In 11153bb:

In theory this is still bad because it will allocate less memory than the user expects, which could lead to writing past the end of the buffer. (Or could it? I suppose that the user can't actually write more memory than is addressable, which this saturation should limit at..)

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 11153bb; successfully ran local tests

@stringhandler

Copy link
Copy Markdown
Contributor Author

It gets saturating_added later anyway

let size_prefixed_bytes = MIN_ALIGN.saturating_add(size_bytes);

@apoelstra apoelstra merged commit 5404648 into BlockstreamResearch:master Jun 22, 2026
24 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