dirclient: don't return too-long responses on decompression failure

There are a couple of places where we forgot to truncate our
return-buffer to its actual size, and instead returned a big bunch
of zeros.  Found while writing the tests in the next commit.

Someday, we'll have ReadBuf and won't have to worry about these
things.
This commit is contained in:
Nick Mathewson 2022-01-28 12:53:07 -05:00
parent 81a49fb6ec
commit 7fdde559d4
1 changed files with 2 additions and 0 deletions

View File

@ -307,12 +307,14 @@ where
let status = futures::select! {
status = stream.read(buf).fuse() => status,
_ = timer => {
result.resize(written_total, 0); // truncate as needed
return Err(Error::DirTimeout);
}
};
let written_in_this_loop = match status {
Ok(n) => n,
Err(other) => {
result.resize(written_total, 0); // truncate as needed
return Err(other.into());
}
};