Skip to content

fix: disallow unknown fields#9

Merged
beer-1 merged 1 commit into
mainfrom
fix/disallow-unknown-fields
May 26, 2026
Merged

fix: disallow unknown fields#9
beer-1 merged 1 commit into
mainfrom
fix/disallow-unknown-fields

Conversation

@beer-1
Copy link
Copy Markdown
Member

@beer-1 beer-1 commented May 20, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced vote extension decoding validation to ensure data integrity and reject malformed input.
    • Improved decompression validation to detect and reject corrupted or trailing data.
  • Tests

    • Added test coverage for rejection of malformed vote extension encoding and compression scenarios.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5cd8ed94-fac7-4986-b947-84e7fc28697b

📥 Commits

Reviewing files that changed from the base of the PR and between ba8bdf9 and 2c79be0.

📒 Files selected for processing (2)
  • abci/strategies/codec/codec.go
  • abci/strategies/codec/codec_test.go

Walkthrough

This PR adds strict canonical encoding validation to protobuf vote extension and zlib decompression codecs. DefaultVoteExtensionCodec.Decode now rejects non-canonical vote extensions by verifying encoded bytes match the expected size. ZLibCompressor.Decompress validates the zlib stream is fully consumed with no trailing bytes. Both implementations are covered by new test cases that verify rejection of padded encodings.

Changes

Canonical Encoding Validation for Vote Extensions

Layer / File(s) Summary
Vote Extension Decoder - Canonical Encoding Validation
abci/strategies/codec/codec.go
DefaultVoteExtensionCodec.Decode adds explicit unmarshal error handling and checks that the input length matches OracleVoteExtension.Size(), returning a formatted error if the encoding is non-canonical (e.g., padded with unknown fields). fmt import added to support formatted error messages.
ZLib Decompressor - Trailing Bytes Validation
abci/strategies/codec/codec.go
ZLibCompressor.Decompress is rewritten to read decompressed data via io.ReadAll, properly handle errors from zlib reader creation and closing, and validate that the zlib stream consumed the entire input, rejecting any remaining trailing bytes.
Tests and Helpers - Canonical Encoding Rejection
abci/strategies/codec/codec_test.go
TestDefaultVoteExtensionCodec adds a subtest that appends unknown-field padding to an encoded vote extension and asserts decoding fails. TestCompressionVoteExtensionCodec adds a subtest that appends trailing zero bytes and asserts decoding fails. Helper function appendUnknownFieldPadding constructs protobuf wire-format unknown fields for test fixtures. encoding/binary import added.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Strict validators hop with glee,
Canonical bytes they filter with care,
No padding sneaks past, no trailing debris—
Each codec now checks with earnest flair!
Protobuf pristine from decompression's air. 🎪

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: disallow unknown fields' directly and concisely describes the main change: enforcing validation to reject unknown fields in codec operations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/disallow-unknown-fields

Comment @coderabbitai help to get the list of available commands and usage tips.

@beer-1 beer-1 merged commit edd4573 into main May 26, 2026
13 of 15 checks passed
@beer-1 beer-1 deleted the fix/disallow-unknown-fields branch May 26, 2026 05:17
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