Skip to content

Formally verify much of the protocol parsing logic + harden size paths - #2970

Draft
michael-grunder wants to merge 10 commits into
developfrom
fix/formal-verification
Draft

michael-grunder wants to merge 10 commits into
developfrom
fix/formal-verification

Conversation

@michael-grunder

Copy link
Copy Markdown
Member

This PR contains several CMBC assisted hardening changes for parsing and data derived size logic.

I had codex and claude identify functions that could be formally verified with CBMC update the logic until it proved sound for any input.

The changes are as follows:

  • Validate RESP bulk and array lengths consistently, rejecting malformed or out-of-range values and disconnecting when framing can no longer be trusted.
  • Validate bulk reply CRLF terminators and disconnect on incomplete payloads.
  • Cap initial allocations for bulk strings and reply arrays, growing buffers as data arrives instead of allocating from server-provided lengths.
  • Grow RedisCluster multibulk replies incrementally and safely clean up partially read replies.
  • Propagate nested RESP parsing failures to callers and stop processing failed replies.
  • Bound LZF decompression buffer growth and reject impossible LZ4 and ZSTD decompressed-size claims before allocating memory.

This is a work in progress that must be extensively tested for correctness, performance, or backward compatibility regressions.

@michael-grunder
michael-grunder force-pushed the fix/formal-verification branch from f444471 to 9ab4d04 Compare October 29, 2026 17:48
* Materialize `zend_string` directly for bulk strings instead of
  using an intermediate heap allocated buffer.
* Reet `errno` each `lzf` iteration
@michael-grunder
michael-grunder force-pushed the fix/formal-verification branch from 9ab4d04 to ad72bff Compare October 29, 2026 17:51

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant