Fix crash when parsing pdf in bug 28170

This code is a can of crashing worms :-7
diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc
index 97994bd..f16ad58 100644
--- a/poppler/JBIG2Stream.cc
+++ b/poppler/JBIG2Stream.cc
@@ -742,13 +742,18 @@
   Guint xx, yy;
 
   slice = new JBIG2Bitmap(0, wA, hA);
-  slice->clearToZero();
-  for (yy = 0; yy < hA; ++yy) {
-    for (xx = 0; xx < wA; ++xx) {
-      if (getPixel(x + xx, y + yy)) {
-	slice->setPixel(xx, yy);
+  if (slice->isOk()) {
+    slice->clearToZero();
+    for (yy = 0; yy < hA; ++yy) {
+      for (xx = 0; xx < wA; ++xx) {
+        if (getPixel(x + xx, y + yy)) {
+	  slice->setPixel(xx, yy);
+        }
       }
     }
+  } else {
+    delete slice;
+    slice = NULL;
   }
   return slice;
 }
@@ -3224,8 +3229,12 @@
 
   // store the region bitmap
   } else {
-    bitmap->setSegNum(segNum);
-    segments->append(bitmap);
+    if (bitmap) {
+      bitmap->setSegNum(segNum);
+      segments->append(bitmap);
+    } else {
+      error(curStr->getPos(), "readGenericRefinementRegionSeg with null bitmap");
+    }
   }
 
   // delete the referenced bitmap