Fix: memory output drainage and add regression test for #2469 - #2472
Conversation
|
Thank you @MakerYuichi ! We will be looking at this next. |
Cover do_copy=true on an empty output (success without allocating) and the non-memory-output rejection, drop unused includes, add the missing EOF newline, remove trailing whitespace and stray blank-line hunks.
|
Validated end to end against a main-identical tree:
This unblocks uniform empty-output draining, which e.g. |
ronaldtse
left a comment
There was a problem hiding this comment.
Thank you @MakerYuichi — clear bug report shape (issue + minimal fix + regression test), exactly how we like them.
Validated end to end against a main-identical tree: the regression test fails on current main with RNP_ERROR_BAD_PARAMETERS exactly as #2469 describes (lazy allocation means an empty memory output has no buffer), and passes with this fix. All three changed paths check out: the !*buf && *len guard keeps the defensive error for the impossible NULL-with-bytes case, the explicit PGP_STREAM_MEMORY check makes wrong-type rejection intentional, and do_copy && *len avoids a pointless malloc(0). No other open PR touches this function. I pushed a small follow-up commit extending the test to the do_copy=true-empty and non-memory-output cases and cleaning up style.
|
@ni4 this one needs your approval (1 of 2 — I've approved): #2472 Small, well-scoped fix by @MakerYuichi for #2469: rnp_output_memory_get_buf() returned BAD_PARAMETERS when draining a valid-but-empty memory output, because the buffer allocates lazily on first write. Now returns SUCCESS with (NULL, 0). Verified against main locally (regression test fails pre-fix, passes after), and it unblocks uniform empty-output draining — e.g. the backup-archive plaintext drain in #2435. CI green. |
ni4
left a comment
There was a problem hiding this comment.
LGTM, thanks! But let's wait till non-approved workflows are finished and green.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2472 +/- ##
=======================================
Coverage 85.40% 85.40%
=======================================
Files 126 126
Lines 22964 22966 +2
=======================================
+ Hits 19612 19614 +2
Misses 3352 3352 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The windows-11-arm leg fails with |
ronaldtse
left a comment
There was a problem hiding this comment.
Approving — the fix is correct and validated end to end (regression test fails on main, passes with the change; no other open PR touches this function).
|
All workflows here should pass (except fuzzing jobs due to google/oss-fuzz#15882 ). Will merge when it is done. |
|
Thank you @MakerYuichi for contributing the fix! |
Description
Fixes an issue where
rnp_output_memory_get_buf()unexpectedly fails withRNP_ERROR_BAD_PARAMETERSwhen draining a legitimately empty memory output (such as a zero-length literal packet or an operation that produced no data).A memory destination that hasn't written any bytes does not allocate an internal buffer, causing
mem_dest_get_memory()to returnNULL. This PR introduces a check to safely returnRNP_SUCCESSwith*len = 0and*buf = NULLif*len == 0on a validPGP_STREAM_MEMORYtype stream, allowing callers to uniformly drain empty memory outputs.Fixes #2469
PR Checklist
clang-formatwasn't available locally, relying on CI check).src/tests/issues/2469.cpp).include/rnp/rnp.h.