[Python-checkins] r54337 - in python/branches/release25-maint: Misc/NEWS Modules/bz2module.c

georg.brandl python-checkins at python.org
Tue Mar 13 13:34:38 CET 2007


Author: georg.brandl
Date: Tue Mar 13 13:34:35 2007
New Revision: 54337

Modified:
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Modules/bz2module.c
Log:
Bug #1622896: fix a rare corner case where the bz2 module raised an
error in spite of a succesful compression.
 (backport from rev. 54336)

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Tue Mar 13 13:34:35 2007
@@ -125,6 +125,9 @@
 Extension Modules
 -----------------
 
+- Bug #1622896: fix a rare corner case where the bz2 module raised an
+  error in spite of a succesful compression.
+
 - Patch #1654417: make operator.{get,set,del}slice use the full range
   of Py_ssize_t.
 

Modified: python/branches/release25-maint/Modules/bz2module.c
==============================================================================
--- python/branches/release25-maint/Modules/bz2module.c	(original)
+++ python/branches/release25-maint/Modules/bz2module.c	Tue Mar 13 13:34:35 2007
@@ -1579,6 +1579,8 @@
 			Util_CatchBZ2Error(bzerror);
 			goto error;
 		}
+		if (bzs->avail_in == 0)
+			break; /* no more input data */
 		if (bzs->avail_out == 0) {
 			bufsize = Util_NewBufferSize(bufsize);
 			if (_PyString_Resize(&ret, bufsize) < 0) {
@@ -1588,8 +1590,6 @@
 			bzs->next_out = BUF(ret) + (BZS_TOTAL_OUT(bzs)
 						    - totalout);
 			bzs->avail_out = bufsize - (bzs->next_out - BUF(ret));
-		} else if (bzs->avail_in == 0) {
-			break;
 		}
 	}
 
@@ -1871,6 +1871,8 @@
 			Util_CatchBZ2Error(bzerror);
 			goto error;
 		}
+		if (bzs->avail_in == 0)
+			break; /* no more input data */
 		if (bzs->avail_out == 0) {
 			bufsize = Util_NewBufferSize(bufsize);
 			if (_PyString_Resize(&ret, bufsize) < 0) {
@@ -1881,8 +1883,6 @@
 			bzs->next_out = BUF(ret) + (BZS_TOTAL_OUT(bzs)
 						    - totalout);
 			bzs->avail_out = bufsize - (bzs->next_out - BUF(ret));
-		} else if (bzs->avail_in == 0) {
-			break;
 		}
 	}
 
@@ -2160,6 +2160,13 @@
 			Py_DECREF(ret);
 			return NULL;
 		}
+		if (bzs->avail_in == 0) {
+			BZ2_bzDecompressEnd(bzs);
+			PyErr_SetString(PyExc_ValueError,
+					"couldn't find end of stream");
+			Py_DECREF(ret);
+			return NULL;
+		}
 		if (bzs->avail_out == 0) {
 			bufsize = Util_NewBufferSize(bufsize);
 			if (_PyString_Resize(&ret, bufsize) < 0) {
@@ -2169,12 +2176,6 @@
 			}
 			bzs->next_out = BUF(ret) + BZS_TOTAL_OUT(bzs);
 			bzs->avail_out = bufsize - (bzs->next_out - BUF(ret));
-		} else if (bzs->avail_in == 0) {
-			BZ2_bzDecompressEnd(bzs);
-			PyErr_SetString(PyExc_ValueError,
-					"couldn't find end of stream");
-			Py_DECREF(ret);
-			return NULL;
 		}
 	}
 


More information about the Python-checkins mailing list