From badd9f799eed7d7efb9357df1e931df1f422f275 Mon Sep 17 00:00:00 2001
From: Rob Landley <rob@landley.net>
Date: Sat, 23 Apr 2016 05:04:37 -0500
Subject: Fiz bzcat segfault reported by John Regehr (bad crc didn't set error
 message).

---
 toys/other/bzcat.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/toys/other/bzcat.c b/toys/other/bzcat.c
index fdad9a01..ff598491 100644
--- a/toys/other/bzcat.c
+++ b/toys/other/bzcat.c
@@ -455,9 +455,6 @@ static void burrows_wheeler_prep(struct bunzip_data *bd, struct bwdata *bw)
   unsigned int *dbuf = bw->dbuf;
   int *byteCount = bw->byteCount;
 
-  // Technically this part is preparation for the burrows-wheeler
-  // transform, but it's quick and convenient to do here.
-
   // Turn byteCount into cumulative occurrence counts of 0 to n-1.
   jj = 0;
   for (ii=0; ii<256; ii++) {
@@ -651,7 +648,10 @@ static char *bunzipStream(int src_fd, int dst_fd)
 
   if (!(i = start_bunzip(&bd,src_fd, 0, 0))) {
     i = write_bunzip_data(bd,bd->bwdata, dst_fd, 0, 0);
-    if (i==RETVAL_LAST_BLOCK && bd->bwdata[0].headerCRC==bd->totalCRC) i = 0;
+    if (i==RETVAL_LAST_BLOCK) {
+      if (bd->bwdata[0].headerCRC==bd->totalCRC) i = 0;
+      else i = RETVAL_DATA_ERROR;
+    }
   }
   flush_bunzip_outbuf(bd, dst_fd);
 
-- 
cgit v1.2.3