Opened 8 years ago
Closed 8 years ago
#39774 closed defect (bug) (fixed)
php 7.1 media uploader bug
Reported by: | drrobotnik | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 4.7.3 | Priority: | normal |
Severity: | normal | Version: | 4.8 |
Component: | Upload | Keywords: | has-patch fixed-major |
Focuses: | Cc: |
Description
In PHP7.1, when you upload a file with the same name multiple times there is a PHP Warning: A non-numeric value encountered in /wp-includes/functions.php on line 2077
.
The warning is a type casting related. All you need to do to fix is change the default string value to null.
I've included a very tiny patch and have tested that it fixes the issue and has no backwards compatibility implications.
Attachments (3)
Change History (13)
#1
@
8 years ago
- Milestone changed from Awaiting Review to 4.7.3
Hi @drrobotnik, thanks for the ticket and the patch!
$number = ''
was added in [3255] and has not changed since then.
Shouldn't it be $number = 0
instead of null
though?
#2
@
8 years ago
Hey @SergeyBiryukov,
Null shouldn't hurt anything, but yeah that makes sense. I was looking at an empty string and thinking unset.
I've attached the updated patch.
While I was testing the change I came across another issue a few lines down:
PHP Fatal error: Maximum execution time of 30 seconds exceeded in /wp-includes/functions.php on line 2098
<?php while ( file_exists( $dir . "/$filename" ) ) { if ( '' === "$number$ext" ) { $filename = "$filename-" . ++$number; } else { $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . ++$number . $ext, $filename ); } }
It was fixed by changing while()
to if()
. I see a few of these in functions.php. What's odd was it only happened when I uploaded a gif (963 KB), but not when I uploaded a jpg (1.3 MB). Should I open a separate ticket?
#3
@
8 years ago
- Keywords has-patch added
Ah, I was wrong, we can't set $number
to 0
, because it needs to be an empty string on first iteration. Otherwise, it causes the infinite loop issue that you experienced.
functions.diff works fine, I'd just like to make the type casting explicit just in case.
39774.patch also makes it more consistent with the preceding block.
#5
@
8 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 40039:
#6
@
8 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for 4.7.3 consideration.
wp-includes/functions.php, changes default type to null in order to fix bug in WP while using PHP 7.1