Skip to content

Commit 7e94790

Browse files
committed
Fix #80654: file_get_contents() maxlen fails above (2**31)-1 bytes
We remove the arbitrary restriction to `INT_MAX`; it is superfluous on 32bit systems where `ZEND_LONG_MAX == INT_MAX` anyway, and not useful on 64bit systems, where larger files should be readable, if the `memory_limit` is large enough. Closes GH-6648.
1 parent 217b9e7 commit 7e94790

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
semicolon) (cmb)
1111
. Fixed bug #70091 (Phar does not mark UTF-8 filenames in ZIP archives). (cmb)
1212

13+
- Standard:
14+
. Fixed bug #80654 (file_get_contents() maxlen fails above (2**31)-1 bytes).
15+
(cmb)
16+
1317
- Zip:
1418
. Fixed bug #80648 (Fix for bug 79296 should be based on runtime version).
1519
(cmb, Remi)

ext/standard/file.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,6 @@ PHP_FUNCTION(file_get_contents)
564564
RETURN_FALSE;
565565
}
566566

567-
if (maxlen > INT_MAX) {
568-
php_error_docref(NULL, E_WARNING, "maxlen truncated from " ZEND_LONG_FMT " to %d bytes", maxlen, INT_MAX);
569-
maxlen = INT_MAX;
570-
}
571567
if ((contents = php_stream_copy_to_mem(stream, maxlen, 0)) != NULL) {
572568
RETVAL_STR(contents);
573569
} else {

ext/standard/streamsfuncs.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,6 @@ PHP_FUNCTION(stream_get_contents)
456456
}
457457
}
458458

459-
if (maxlen > INT_MAX) {
460-
php_error_docref(NULL, E_WARNING, "maxlen truncated from " ZEND_LONG_FMT " to %d bytes", maxlen, INT_MAX);
461-
maxlen = INT_MAX;
462-
}
463459
if ((contents = php_stream_copy_to_mem(stream, maxlen, 0))) {
464460
RETURN_STR(contents);
465461
} else {

0 commit comments

Comments
 (0)