1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 09:31:16 +02:00

Merge branch 'fix/avoid-large-stack-buffers' of https://github.com/dtzWill/nix

This commit is contained in:
Eelco Dolstra 2018-03-22 13:19:25 +01:00
commit f87e286e82
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 27 additions and 26 deletions

View file

@ -40,14 +40,14 @@ static void dumpContents(const Path & path, size_t size,
AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (!fd) throw SysError(format("opening file '%1%'") % path);
unsigned char buf[65536];
std::vector<unsigned char> buf(65536);
size_t left = size;
while (left > 0) {
size_t n = left > sizeof(buf) ? sizeof(buf) : left;
readFull(fd.get(), buf, n);
size_t n = left > buf.size() ? buf.size() : left;
readFull(fd.get(), buf.data(), n);
left -= n;
sink(buf, n);
sink(buf.data(), n);
}
writePadding(size, sink);
@ -146,14 +146,14 @@ static void parseContents(ParseSink & sink, Source & source, const Path & path)
sink.preallocateContents(size);
unsigned long long left = size;
unsigned char buf[65536];
std::vector<unsigned char> buf(65536);
while (left) {
checkInterrupt();
unsigned int n = sizeof(buf);
if ((unsigned long long) n > left) n = left;
source(buf, n);
sink.receiveContents(buf, n);
auto n = buf.size();
if ((unsigned long long)n > left) n = left;
source(buf.data(), n);
sink.receiveContents(buf.data(), n);
left -= n;
}