Make WordPress Core

Opened 12 months ago

Closed 12 months ago

Last modified 12 months ago

#60446 closed defect (bug) (invalid)

Unable to upload JSON files that has empty array

Reported by: puvipavan's profile puvipavan Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch
Focuses: Cc:

Description

WordPress uses the function finfo_file to detect the mime type of the file if it’s not an image.

PHP uses the file library from here: https://github.com/file/file/ which is a core of the file command we use in most of the Linux based systems.

Issue resides in that library. It expects values inside an array. If empty array is found, then it doesn’t detect it as JSON.

For example:

[
  {
    "id": "123",
    "labels": []
  }
]

Above string is valid JSON according to RFC-7159/RFC-8259 standards. But due to the issue within that library, it doesn’t detect as JSON.

Looks like WP team knew about the issues within that library. That’s why they have explicitly added other file types that were detected as text/plain by that library and whitelisted it here: https://github.com/WordPress/WordPress/blob/ea8080d8c80c124f9d1a6e42d6e95a785231f661/wp-includes/functions.php#L3204-L3209

Following Comment confirms it: https://github.com/WordPress/WordPress/blob/ea8080d8c80c124f9d1a6e42d6e95a785231f661/wp-includes/functions.php#L3200C4-L3201C1

Therefore it's better if we can add application/json too since it will cover edge cases like above.

I will create a PR.

Attachments (2)

60446.diff (385 bytes) - added by puvipavan 12 months ago.
Fix
60446-new.diff (386 bytes) - added by puvipavan 12 months ago.
Patch for https://github.com/WordPress/wordpress-develop/pull/6038/commits/21c97f354265df83557e5760c4d149bf4c45967a

Download all attachments as: .zip

Change History (7)

@puvipavan
12 months ago

Fix

This ticket was mentioned in PR #6038 on WordPress/wordpress-develop by Puvipavan.


12 months ago
#1

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/60446

WordPress uses the function finfo_file to detect the mime type of the file if it’s not an image.
PHP uses the file library from here: https://github.com/file/file/ which is a core of the file command we use in most of the Linux based systems.
Issue resides in that library. It expects values inside an array. If empty array is found, then it doesn’t detect it as JSON.
For example:

[
  {
    "id": "123",
    "labels": []
  }
]

Above string is valid JSON according to RFC-7159/RFC-8259 standards. But due to the issue within that library, it doesn’t detect as JSON.

Looks like WP team knew about the issues within that library. That’s why they have explicitly added other file types that were detected as text/plain by that library and whitelisted it here: https://github.com/WordPress/WordPress/blob/ea8080d8c80c124f9d1a6e42d6e95a785231f661/wp-includes/functions.php#L3204-L3209

Following Comment confirms it: https://github.com/WordPress/WordPress/blob/ea8080d8c80c124f9d1a6e42d6e95a785231f661/wp-includes/functions.php#L3200C4-L3201C1

Therefore it's better if we can add application/json too since it will cover edge cases like above.

#2 @puvipavan
12 months ago

Please hold the review for a moment, since I'm unable to replicate with small files.

#3 @puvipavan
12 months ago

  • Resolution set to invalid
  • Status changed from new to closed

Closing this. Something wrong on my end

Puvipavan commented on PR #6038:


12 months ago
#4

Closing this. Something wrong on my end.

#5 @swissspidy
12 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.