af9dc8
Adapted for 5.4, binary patch removed, from:
af9dc8
af9dc8
af9dc8
From f3feddb5b45b5abd93abb1a95044b7e099d51c84 Mon Sep 17 00:00:00 2001
af9dc8
From: Stanislav Malyshev <stas@php.net>
af9dc8
Date: Mon, 18 Jul 2016 22:20:45 -0700
af9dc8
Subject: [PATCH] Partial fix for bug #72613 - do not treat negative returns
af9dc8
 from bz2 as size_t
af9dc8
af9dc8
---
af9dc8
 ext/bz2/bz2.c               |  80 +++++++++++++++++++++++---------------------
af9dc8
 ext/bz2/tests/72613.bz2     | Bin 0 -> 351 bytes
af9dc8
 ext/bz2/tests/bug72613.phpt |  23 +++++++++++++
af9dc8
 3 files changed, 65 insertions(+), 38 deletions(-)
af9dc8
 create mode 100644 ext/bz2/tests/72613.bz2
af9dc8
 create mode 100644 ext/bz2/tests/bug72613.phpt
af9dc8
af9dc8
diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c
af9dc8
index de3250e..7cfcaa8 100644
af9dc8
--- a/ext/bz2/bz2.c
af9dc8
+++ b/ext/bz2/bz2.c
af9dc8
@@ -137,16 +137,20 @@ struct php_bz2_stream_data_t {
af9dc8
 static size_t php_bz2iop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
af9dc8
 {
af9dc8
 	struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *) stream->abstract;
af9dc8
-	size_t ret;
af9dc8
-	
af9dc8
-	ret = BZ2_bzread(self->bz_file, buf, count);
af9dc8
+	int bz2_ret;
af9dc8
+
af9dc8
+	bz2_ret = BZ2_bzread(self->bz_file, buf, count);
af9dc8
 
af9dc8
-	if (ret == 0) {
af9dc8
+	if (bz2_ret < 0) {
af9dc8
+		stream->eof = 1;
af9dc8
+		return -1;
af9dc8
+	}
af9dc8
+	if (bz2_ret == 0) {
af9dc8
 		stream->eof = 1;
af9dc8
 	}
af9dc8
 
af9dc8
-	return ret;
af9dc8
+	return (size_t)bz2_ret;
af9dc8
 }
af9dc8
 
af9dc8
 static size_t php_bz2iop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
af9dc8
 {