Add nil-element validation to flow data models - #8668
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens Flow’s core data model constructors against malformed/untrusted inputs by adding validation that rejects nil elements (and nil nested pointers) inside otherwise non-nil container types. This reduces the risk of panics or inconsistent IDs when decoding network-provided payloads (e.g., CBOR null → Go nil).
Changes:
- Add
nil-element checks for nested lists (e.g.,ExecutionResult.Chunks) during payload/result construction. - Validate nested pointer fields by reconstructing through constructors (e.g.,
HeaderBody.LastViewTC, HotStuffTimeoutObject.LastViewTC,ChunkDataPack.Collection). - Extend unit tests to cover the new rejection paths.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| model/flow/payload.go | Rejects nil chunk entries within non-nil execution results in payloads. |
| model/flow/payload_test.go | Adds coverage for rejecting a payload containing a result with a nil chunk element. |
| model/flow/header.go | Validates LastViewTC via NewTimeoutCertificate instead of accepting nested nil pointers. |
| model/flow/header_test.go | Adds coverage for rejecting a header body with LastViewTC.NewestQC == nil. |
| model/flow/execution_result.go | Rejects nil chunk elements in ExecutionResult.Chunks. |
| model/flow/execution_result_test.go | Adds coverage for rejecting an execution result containing a nil chunk element. |
| model/flow/chunk.go | Validates optional Collection via NewCollection to reject nil transaction elements. |
| model/flow/chunk_test.go | Adds coverage for rejecting a chunk data pack whose collection contains a nil transaction. |
| model/flow/block_test.go | Updates block malleability test to account for stricter header-body validation. |
| consensus/hotstuff/model/timeout.go | Validates LastViewTC via flow.NewTimeoutCertificate and uses the validated TC for comparisons/return value. |
| consensus/hotstuff/model/timeout_test.go | Adjusts/extends tests to align with stricter TC validity requirements and new nil-nested-pointer rejection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| unittest.RequireEntityNonMalleable( | ||
| t, | ||
| unittest.FullBlockFixture(), | ||
| blockWithLastViewTC(), | ||
| unittest.WithFieldGenerator("HeaderBody.ParentView", func() uint64 { | ||
| return block.View - 1 // ParentView must stay below View, so set it to View-1 |
There was a problem hiding this comment.
Updated in commit 0f35865765: TestBlockMalleability now passes the same block instance into RequireEntityNonMalleable, so the ParentView generator is consistent with the entity under test.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-authored-by: zhangchiqing <811374+zhangchiqing@users.noreply.github.com>
Add nil-element validation to more flow models: Hotstuff timeout, execution result, chunk data pack, block header, etc.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.