Blame SOURCES/djvulibre-3.5.27-unsigned-short-overflow.patch

a9380a
diff --git a/libdjvu/GBitmap.cpp b/libdjvu/GBitmap.cpp
a9380a
index c2fdbe4..e271a1d 100644
a9380a
--- a/libdjvu/GBitmap.cpp
a9380a
+++ b/libdjvu/GBitmap.cpp
a9380a
@@ -69,6 +69,7 @@
a9380a
 #include <stddef.h>
a9380a
 #include <stdlib.h>
a9380a
 #include <string.h>
a9380a
+#include <limits.h>
a9380a
 
a9380a
 // - Author: Leon Bottou, 05/1997
a9380a
 
a9380a
@@ -1284,6 +1285,8 @@ GBitmap::decode(unsigned char *runs)
a9380a
   // initialize pixel array
a9380a
   if (nrows==0 || ncolumns==0)
a9380a
     G_THROW( ERR_MSG("GBitmap.not_init") );
a9380a
+  if (ncolumns > USHRT_MAX - border)
a9380a
+    G_THROW("GBitmap: row size exceeds maximum (corrupted file?)");
a9380a
   bytes_per_row = ncolumns + border;
a9380a
   if (runs==0)
a9380a
     G_THROW( ERR_MSG("GBitmap.null_arg") );