From: mcq8 Date: Thu, 4 Dec 2014 16:36:44 +0000 (+0100) Subject: Fix bug #68532: convert.base64-encode omits padding bytes X-Git-Tag: PRE_NATIVE_TLS_MERGE~13^2~1^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86f18755362b594c519ccde37c3b3f98158b591e;p=php Fix bug #68532: convert.base64-encode omits padding bytes --- diff --git a/ext/standard/tests/file/bug68532.phpt b/ext/standard/tests/file/bug68532.phpt new file mode 100644 index 0000000000..7d1a0cea9a --- /dev/null +++ b/ext/standard/tests/file/bug68532.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #68532: convert.base64-encode omits padding bytes +--FILE-- + +--CLEAN-- + +--EXPECT-- +memoryStream = dGVzdA== +fileStream = dGVzdA== diff --git a/ext/standard/tests/file/stream_rfc2397_007.phpt b/ext/standard/tests/file/stream_rfc2397_007.phpt index 8a6f3155dd..b62f19cd37 100644 --- a/ext/standard/tests/file/stream_rfc2397_007.phpt +++ b/ext/standard/tests/file/stream_rfc2397_007.phpt @@ -27,6 +27,7 @@ foreach($streams as $stream) var_dump(feof($fp)); echo "===GETC===\n"; var_dump(fgetc($fp)); + var_dump(fgetc($fp)); var_dump(ftell($fp)); var_dump(feof($fp)); echo "===REWIND===\n"; @@ -94,6 +95,7 @@ int(5) bool(false) ===GETC=== string(1) "5" +bool(false) int(6) bool(true) ===REWIND=== diff --git a/main/streams/memory.c b/main/streams/memory.c index e6d0baaa86..f73c12f7d7 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -87,15 +87,19 @@ static size_t php_stream_memory_read(php_stream *stream, char *buf, size_t count php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract; assert(ms != NULL); - if (ms->fpos + count >= ms->fsize) { - count = ms->fsize - ms->fpos; + if (ms->fpos == ms->fsize) { stream->eof = 1; - } - if (count) { - assert(ms->data!= NULL); - assert(buf!= NULL); - memcpy(buf, ms->data+ms->fpos, count); - ms->fpos += count; + count = 0; + } else { + if (ms->fpos + count >= ms->fsize) { + count = ms->fsize - ms->fpos; + } + if (count) { + assert(ms->data!= NULL); + assert(buf!= NULL); + memcpy(buf, ms->data+ms->fpos, count); + ms->fpos += count; + } } return count; }