mirror of
https://github.com/NixOS/nix
synced 2025-06-26 15:51:15 +02:00
Make NAR header check more robust
Changes std::bad_alloc into bad archive: input doesn't look like a Nix archive
This commit is contained in:
parent
7ccdcc7fed
commit
44e86304b6
3 changed files with 5 additions and 4 deletions
|
@ -268,16 +268,17 @@ void readPadding(size_t len, Source & source)
|
|||
size_t readString(unsigned char * buf, size_t max, Source & source)
|
||||
{
|
||||
auto len = readNum<size_t>(source);
|
||||
if (len > max) throw Error("string is too long");
|
||||
if (len > max) throw SerialisationError("string is too long");
|
||||
source(buf, len);
|
||||
readPadding(len, source);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
string readString(Source & source)
|
||||
string readString(Source & source, size_t max)
|
||||
{
|
||||
auto len = readNum<size_t>(source);
|
||||
if (len > max) throw SerialisationError("string is too long");
|
||||
std::string res(len, 0);
|
||||
source((unsigned char*) res.data(), len);
|
||||
readPadding(len, source);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue