about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/references.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libstore/references.cc b/src/libstore/references.cc
index aba4ef01072f..6f34b1497393 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 <dirent.h>
 #include <fcntl.h>
 
+#include <stdint.h>
+
 
 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);