zstream: report invalid record context without assertions - #19097
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The payload limit is enforced too late, and regression coverage is missing.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates zstream validation to report malformed contexts and oversized DRR_BEGIN payloads as offset-aware errors instead of assertions.
Changes:
- Replaces context assertions with validation errors.
- Preserves compound-stream
DRR_ENDhandling. - Requires early payload-size validation and regression coverage before approval.
File summaries
| File | Review summary |
|---|---|
cmd/zstream/zstream_validate.c |
Critical: enforce the BEGIN payload cap before allocation/read. Nit: add regression tests for invalid contexts, oversized payloads, and offsets. |
Review details
Suppressed comments (1)
cmd/zstream/zstream_validate.c:95
- Please add regression coverage for the new validation paths (nested
DRR_BEGIN, non-DRR_ENDrecords after a substream, and oversizedDRR_BEGINpayloads), including the reported offsets. The existingzstream_validate_001_negtest only exercises a malformedDRR_WRITE, so it would not catch these paths regressing to an assertion or disappearing.
if (context->nesting != 0) {
errx(1, "nested DRR_BEGIN record at offset %llu",
(u_longlong_t)item->dp_stream_offset);
}
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
d8277ad to
d7021dc
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Retain the nesting invariant assertion to avoid masking internal state corruption.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Lite
d7021dc to
abba1e3
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Retain the non-negative nesting assertion in cmd/zstream/zstream_validate.c.
Review details
Suppressed comments (1)
cmd/zstream/zstream_validate.c:117
- The non-negative nesting invariant is no longer asserted here: removing
VERIFY3S(context->nesting, >=, 0)means an internal state violation is silently handled as an external END/context error (or can be accepted as a compound conclusion). The PR description says this invariant should remain internal; retain the assertion before thenesting > 0branch while still reporting valid zero-nesting END records witherrx.
if (context->nesting > 0) {
context->nesting--;
} else if (context->compound &&
IS_CONCLUSION(drr, DRR_END)) {
context->concluded = B_TRUE;
- Files reviewed: 6/6 changed files
- Comments generated: 0 new
- Review effort level: Lite
abba1e3 to
8b2a995
Compare
|
@GarthSnyder would you mind reviewing this. |
GarthSnyder
left a comment
There was a problem hiding this comment.
These changes look correct and helpful. Thanks for working on this, @matthiasgoergens.
There's an existing test-stream-creation-scripts directory underneath the ZTS zstream directory which contains Python scripts that generate some of the other test streams. Those scripts aren't run at test time and that directory isn't currently present in a deployed ZTS, but the general pattern is similar. make-invalid-context-streams.py could plausibly either stay where it is ("It's part of the actual test!") or move into that directory ("It's a Python script that generates test streams!").
Stream framing and BEGIN payload size depend on the input. Report invalid values as ordinary errors with the record offset instead of terminating through VERIFY assertions. Reject oversized BEGIN payloads before allocating or reading them. Track compound-stream conclusions explicitly so valid compound sends remain accepted while stray END records and records after a conclusion are rejected. Add ZTS coverage for malformed streams in both byte orders and for valid compound streams. Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com>
8b2a995 to
28dcb42
Compare
|
Thanks for the review. I kept |
Stream framing and BEGIN payload size depend on the input. Report invalid values as ordinary errors with the record offset instead of terminating through VERIFY assertions. Reject oversized BEGIN payloads before allocating or reading them. Track compound-stream conclusions explicitly so valid compound sends remain accepted while stray END records and records after a conclusion are rejected. Add ZTS coverage for malformed streams in both byte orders and for valid compound streams. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Garth Snyder <garth@garthsnyder.com> Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com> Closes openzfs#19097
Report invalid stream context and oversized BEGIN payloads as ordinary
zstreamerrors, with the record offset, instead of terminating through assertions.Preserve the existing handling of END records: compound sends have a concluding END outside an individual substream. The non-negative nesting assertion remains an internal invariant.