Make WordPress Core

Opened 4 weeks ago

Closed 4 weeks ago

#63551 closed defect (bug) (invalid)

Long filenames are truncated by sanitize_file_name()

Reported by: leedxw's profile leedxw Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.8
Component: Upload Keywords:
Focuses: Cc:

Description

Filenames over 112 characters will be truncated on upload.

It's not clear if this is a php quirk (it occurs under 7.4 and 8.3) or is intended but undocumented behaviour.

https://developer.wordpress.org/reference/functions/sanitize_file_name/ doesn't mention that long files are truncated.

Looking at the code, this doesn't seem to be the explicit intent? The truncation happens with call_user_func_array()

$ wp shell
wp> sanitize_file_name("this-file-name-ends-with-s-dot-jpg-and-the-base-label-consists-of-121-characters-but-will-get-truncated-to-110-characters.jpg");
=> string(114) "this-file-name-ends-with-s-dot-jpg-and-the-base-label-consists-of-121-characters-but-will-get-truncated-to-110.jpg"
wp> sanitize_file_name("this-file-name-ends-with-s-dot-jpg-and-the-base-label-consists-of-121-characters-but-will-get-truncated-to-110-characters.jpeg");
=> string(115) "this-file-name-ends-with-s-dot-jpg-and-the-base-label-consists-of-121-characters-but-will-get-truncated-to-110.jpeg"

Change History (2)

#1 @leedxw
4 weeks ago

Ah, sorry - this appears to be caused by a plugin.

#2 @leedxw
4 weeks ago

  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.