summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-09-15 20:56:50 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-09-15 20:56:50 +0200
commit7f59516611b65dee598966034d526ff1e6e00cf5 (patch)
tree5812b706c0b42f7d39462dc2cd1f7dd455bcc744
parent1f34063b3adfde1d38198209519ebc9ceda2099e (diff)
decompress: Return better io error for BUF_ERROR
Use new MaxTooSmall. As the comment notes tho, it might be that we are lacking input as well, but until I figure out how to test for that case and determine the cause, lets at least return a more specific error.
-rw-r--r--src/decompress_lzma.cc13
-rw-r--r--src/decompress_z.cc13
2 files changed, 20 insertions, 6 deletions
diff --git a/src/decompress_lzma.cc b/src/decompress_lzma.cc
index 6baea18..299803d 100644
--- a/src/decompress_lzma.cc
+++ b/src/decompress_lzma.cc
@@ -63,9 +63,16 @@ class XzReader : public io::Reader {
if (!in_eof_)
buffer_->consume(stream_.next_in - rptr);
} else {
- return std::unexpected(
- ret == LZMA_DATA_ERROR
- ? io::ReadError::InvalidData : io::ReadError::Error);
+ switch (ret) {
+ case LZMA_DATA_ERROR:
+ return std::unexpected(io::ReadError::InvalidData);
+ case LZMA_BUF_ERROR:
+ // Tricky, could also be because of too little input.
+ // TODO: Improve logic here if we can
+ return std::unexpected(io::ReadError::MaxTooSmall);
+ default:
+ return std::unexpected(io::ReadError::Error);
+ }
}
return got;
}
diff --git a/src/decompress_z.cc b/src/decompress_z.cc
index f9f87ae..e888e77 100644
--- a/src/decompress_z.cc
+++ b/src/decompress_z.cc
@@ -62,9 +62,16 @@ class DecompressReader : public io::Reader {
if (!in_eof_)
buffer_->consume(stream_.next_in - rptr);
} else {
- return std::unexpected(
- ret == Z_DATA_ERROR
- ? io::ReadError::InvalidData : io::ReadError::Error);
+ switch (ret) {
+ case Z_DATA_ERROR:
+ return std::unexpected(io::ReadError::InvalidData);
+ case Z_BUF_ERROR:
+ // Tricky, could also be because of too little input.
+ // TODO: Improve logic here if we can
+ return std::unexpected(io::ReadError::MaxTooSmall);
+ default:
+ return std::unexpected(io::ReadError::Error);
+ }
}
return got;
}