-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
istream/Length: implement length checks in _FillBucketList()
Fixes the new (failing) unit tests.
- Loading branch information
1 parent
bcc1f74
commit eb45205
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// author: Max Kellermann <[email protected]> | ||
|
||
#include "LengthIstream.hxx" | ||
#include "Bucket.hxx" | ||
|
||
#include <stdexcept> | ||
|
||
|
@@ -21,6 +22,28 @@ LengthIstream::_Skip(off_t length) noexcept | |
return nbytes; | ||
} | ||
|
||
void | ||
LengthIstream::_FillBucketList(IstreamBucketList &list) | ||
{ | ||
IstreamBucketList tmp; | ||
FillBucketListFromInput(tmp); | ||
|
||
const bool maybe_more = tmp.HasMore() || tmp.HasNonBuffer(); | ||
const std::size_t size = tmp.GetTotalBufferSize(); | ||
|
||
if ((off_t)size > remaining) { | ||
Destroy(); | ||
throw std::runtime_error{"Too much data in stream"}; | ||
} | ||
|
||
if (!maybe_more && (off_t)size < remaining) { | ||
Destroy(); | ||
throw std::runtime_error{"Premature end of stream"}; | ||
} | ||
|
||
list.SpliceBuffersFrom(std::move(tmp)); | ||
} | ||
|
||
Istream::ConsumeBucketResult | ||
LengthIstream::_ConsumeBucketList(std::size_t nbytes) noexcept | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters