This patch to libgo lets it report "len out of range" when making a
slice with a very large length.  This is not strictly necessary as it
already check for a very large capacity, but since the capacity is often
implicit this patch gives a better error.  Bootstrapped and ran Go
testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.  Will
commit to 4.8 branch when it is open.

Ian

diff -r cdf7917ba5bf libgo/runtime/go-make-slice.c
--- a/libgo/runtime/go-make-slice.c	Wed Oct 09 20:50:33 2013 -0700
+++ b/libgo/runtime/go-make-slice.c	Thu Oct 10 17:44:40 2013 -0700
@@ -34,7 +34,10 @@
   std = (const struct __go_slice_type *) td;
 
   ilen = (intgo) len;
-  if (ilen < 0 || (uintptr_t) ilen != len)
+  if (ilen < 0
+      || (uintptr_t) ilen != len
+      || (std->__element_type->__size > 0
+	  && len > MaxMem / std->__element_type->__size))
     runtime_panicstring ("makeslice: len out of range");
 
   icap = (intgo) cap;

Reply via email to