Blob Blame History Raw
diff --git a/common/rfb/PixelFormat.cxx b/common/rfb/PixelFormat.cxx
index 76051dc..a9d015d 100644
--- a/common/rfb/PixelFormat.cxx
+++ b/common/rfb/PixelFormat.cxx
@@ -75,7 +75,8 @@ PixelFormat::PixelFormat(int b, int d, bool e, bool t,
     redMax(rm), greenMax(gm), blueMax(bm),
     redShift(rs), greenShift(gs), blueShift(bs)
 {
-  assert(isSane());
+  if (!isSane())
+    throw Exception("invalid pixel format");
 
   updateState();
 }
@@ -672,8 +673,16 @@ bool PixelFormat::isSane(void)
     return false;
 
   totalBits = bits(redMax) + bits(greenMax) + bits(blueMax);
-  if (totalBits > bpp)
+  if (totalBits > depth)
+    return false;
+
+  if ((bits(redMax) + redShift) > bpp)
+    return false;
+  if ((bits(greenMax) + greenShift) > bpp)
     return false;
+  if ((bits(blueMax) + blueShift) > bpp)
+    return false;
+
 
   if (((redMax << redShift) & (greenMax << greenShift)) != 0)
     return false;