Handle short image reads#518
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #518 +/- ##
==========================================
+ Coverage 73.41% 73.79% +0.38%
==========================================
Files 113 113
Lines 12586 12643 +57
==========================================
+ Hits 9239 9329 +90
+ Misses 3347 3314 -33
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
2ec03ed to
466c3c1
Compare
7e7cdbb to
93fc1cc
Compare
There was a problem hiding this comment.
Pull request overview
This pull request addresses issue #507 by making raw and EWF image readers handle positive short reads safely, ensuring scanners only see initialized bytes and that page-size semantics remain consistent when reads are truncated (e.g., due to EOF or live truncation).
Changes:
- Introduces safe “shrink-to-actual-bytes-read” behavior for
sbuf_tconstruction when a read returns fewer bytes than requested (raw + EWF). - Updates raw reader logic to use
gcount()and treat positive short reads as valid buffers (and not scan unread allocation tail). - Adds regression tests for real-world raw truncation behavior on Linux and for EWF short-read/EOF behavior (when libewf is available).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/image_process.cpp |
Implements short-read-safe sbuf_t construction for EWF/raw readers and correct raw short-read handling via gcount(). |
src/test_be3.cpp |
Adds tests covering raw truncation short reads (Linux) and EWF short-read/EOF behavior (HAVE_LIBEWF). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| static sbuf_t *shrink_sbuf(sbuf_t *sbuf, const pos0_t &pos0, size_t pagesize, size_t bytes_read) | ||
| { | ||
| auto *short_sbuf = sbuf_t::sbuf_malloc(pos0, bytes_read, std::min(pagesize, bytes_read)); | ||
| memcpy(short_sbuf->malloc_buf(), sbuf->malloc_buf(), bytes_read); | ||
| delete sbuf; | ||
| return short_sbuf; | ||
| } |
Codex-authored fix for #507.
Closes #507
What changed
Validation
make -s -j4 -C src check TESTS=test_be