diff --git a/src/libstore/references.cc b/src/libstore/references.cc index aba4ef010..6f34b1497 100644 --- a/src/libstore/references.cc +++ b/src/libstore/references.cc @@ -1,3 +1,5 @@ +#define __STDC_LIMIT_MACROS + #include "references.hh" #include "hash.hh" #include "util.hh" @@ -11,6 +13,8 @@ #include #include +#include + namespace nix { @@ -76,6 +80,9 @@ void checkPath(const string & path, AutoCloseFD fd = open(path.c_str(), O_RDONLY); if (fd == -1) throw SysError(format("opening file `%1%'") % path); + if (st.st_size >= SIZE_MAX) + throw Error(format("cannot allocate %1% bytes") % st.st_size); + unsigned char * buf = new unsigned char[st.st_size]; readFull(fd, buf, st.st_size);