Skip to content

Commit a0d848f

Browse files
author
Julien Pauli
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Updated NEWS Fix bug #68532: convert.base64-encode omits padding bytes
2 parents 4cda982 + d43d066 commit a0d848f

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

ext/standard/tests/file/bug68532.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #68532: convert.base64-encode omits padding bytes
3+
--FILE--
4+
<?php
5+
$testString = 'test';
6+
$stream = fopen('php://memory','r+');
7+
fwrite($stream, $testString);
8+
rewind($stream);
9+
$filter = stream_filter_append($stream, 'convert.base64-encode');
10+
echo "memoryStream = " . stream_get_contents($stream).PHP_EOL;
11+
12+
13+
$fileStream = fopen(__DIR__ . '/base64test.txt','w+');
14+
fwrite($fileStream , $testString);
15+
rewind($fileStream );
16+
$filter = stream_filter_append($fileStream , 'convert.base64-encode');
17+
echo "fileStream = " . stream_get_contents($fileStream ).PHP_EOL;
18+
?>
19+
--CLEAN--
20+
<?php
21+
unlink(__DIR__ . '/base64test.txt');
22+
?>
23+
--EXPECT--
24+
memoryStream = dGVzdA==
25+
fileStream = dGVzdA==

ext/standard/tests/file/stream_rfc2397_007.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ foreach($streams as $stream)
2727
var_dump(feof($fp));
2828
echo "===GETC===\n";
2929
var_dump(fgetc($fp));
30+
var_dump(fgetc($fp));
3031
var_dump(ftell($fp));
3132
var_dump(feof($fp));
3233
echo "===REWIND===\n";
@@ -94,6 +95,7 @@ int(5)
9495
bool(false)
9596
===GETC===
9697
string(1) "5"
98+
bool(false)
9799
int(6)
98100
bool(true)
99101
===REWIND===

main/streams/memory.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,19 @@ static size_t php_stream_memory_read(php_stream *stream, char *buf, size_t count
8787
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
8888
assert(ms != NULL);
8989

90-
if (ms->fpos + count >= ms->fsize) {
91-
count = ms->fsize - ms->fpos;
90+
if (ms->fpos == ms->fsize) {
9291
stream->eof = 1;
93-
}
94-
if (count) {
95-
assert(ms->data!= NULL);
96-
assert(buf!= NULL);
97-
memcpy(buf, ms->data+ms->fpos, count);
98-
ms->fpos += count;
92+
count = 0;
93+
} else {
94+
if (ms->fpos + count >= ms->fsize) {
95+
count = ms->fsize - ms->fpos;
96+
}
97+
if (count) {
98+
assert(ms->data!= NULL);
99+
assert(buf!= NULL);
100+
memcpy(buf, ms->data+ms->fpos, count);
101+
ms->fpos += count;
102+
}
99103
}
100104
return count;
101105
}

0 commit comments

Comments
 (0)