Page MenuHomePhabricator

Exif passing null to preg_match()
Closed, ResolvedPublic

Description

When uploading the below file the following deprecation error is raised by PHP 8.1 (likely because GPS/GPSLatitudeRef is empty):

Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in mediawiki/includes/media/Exif.php on line 623

JDB 2022-05-14 Bucovice station.jpg (3,024×4,032 px, 3 MB)

MediaWiki core version a75de5ee61e46ed3367c4bc3de13ff452c723999

Event Timeline

Hmm, yes, oops! I was attempting a bit of debugging and forgot to remove my code! The actual line is that of the preg_match() above there, on line 623.

Hmm, yes, oops! I was attempting a bit of debugging and forgot to remove my code! The actual line is that of the preg_match() above there, on line 623.

Haha, that's ok. I wasn't sure if we had some weird opcache corruption or something thrown in the mix! :)

I'm not really sure if null counts as valid ASCII... But presumably MW is/was allowing it as is.

Add a if ( $in === null ) { return true; } near the top?

Change 832734 had a related patch set uploaded (by Samwilson; author: Samwilson):

[mediawiki/core@master] Account for null values in Exif data

https://gerrit.wikimedia.org/r/832734

That'd work for this one, but if a null value has been considered valid for 'ascii' tags, perhaps it should also be for tags of all types? We could put the null check in Exif::validate() instead.

Also, and maybe I should be raising this as a separate issue (but all I'm trying to do is upload a weird-exif file so for now I'll stick this here), I'm getting another null deprecation:

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in mediawiki/includes/media/FormatMetadata.php on line 1328

I'll make a patch that does both these.

Change 832734 merged by jenkins-bot:

[mediawiki/core@master] Account for null values in Exif data

https://gerrit.wikimedia.org/r/832734

Change #1114706 had a related patch set uploaded (by Jforrester; author: Samwilson):

[mediawiki/core@REL1_39] Account for null values in Exif data

https://gerrit.wikimedia.org/r/1114706

Change #1114706 merged by jenkins-bot:

[mediawiki/core@REL1_39] Account for null values in Exif data

https://gerrit.wikimedia.org/r/1114706