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