Make WordPress Core

Opened 9 years ago

Last modified 4 weeks ago

#42838 new defect (bug)

Manipulating uploads and images can break when using stream wrappers

Reported by: calin Owned by:
Priority: normal Milestone: Awaiting Review
Component: Media Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

When using PHP stream wrappers for storing uploads into object storages (like S3 or Google Cloud Storage) some things break because in this context a directory merely a path which ends in a '/'.

PHP's builtin dirname always returns the path without the trailing slash. On regular filesystems this is not a problem since a and a/ are equivalent, but in the context of object storages this pose some issues.

I'm attaching a patch which always add a trailing slash when the code expects to work with directories.

Attachments (1)

dirname.diff (2.1 KB ) - added by calin 9 years ago.

Download all attachments as: .zip

Change History (6)

@calin
9 years ago

#1 @pento
8 years ago

  • Keywords has-patch added
  • Version trunk

#2 @sabernhardt
6 years ago

  • Component GeneralMedia
  • Keywords needs-refresh added

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


6 years ago

This ticket was mentioned in PR #12261 on WordPress/wordpress-develop by @arkaprabhachowdhury.


3 months ago
#4

  • Keywords has-unit-tests added; needs-refresh removed

## Summary

  • preserve trailing slashes for stream-wrapper directories before inheriting file permissions
  • use the helper in upload handling and both image editor implementations
  • add strict stream-wrapper regression coverage for uploads plus nested GD and Imagick saves

## Testing

  • php vendor/bin/phpcbf --standard=phpcs.xml.dist src/wp-includes/functions.php src/wp-admin/includes/file.php src/wp-includes/class-wp-image-editor-gd.php src/wp-includes/class-wp-image-editor-imagick.php tests/phpunit/includes/class-wp-test-strict-dir-stream.php tests/phpunit/tests/upload.php tests/phpunit/tests/image/editorGd.php tests/phpunit/tests/image/editorImagick.php
  • php vendor/bin/phpcs --standard=phpcs.xml.dist src/wp-includes/functions.php src/wp-admin/includes/file.php src/wp-includes/class-wp-image-editor-gd.php src/wp-includes/class-wp-image-editor-imagick.php tests/phpunit/includes/class-wp-test-strict-dir-stream.php tests/phpunit/tests/upload.php tests/phpunit/tests/image/editorGd.php tests/phpunit/tests/image/editorImagick.php
  • npm run test:php -- tests/phpunit/tests/upload.php tests/phpunit/tests/image/editorGd.php tests/phpunit/tests/image/editorImagick.php --filter test_wp_upload_bits_should_support_stream_wrapper_directories|test_save_to_nested_stream_path|test_nested_streams (fails locally because the Docker Desktop Linux engine is unavailable)
  • php vendor/bin/phpunit tests/phpunit/tests/upload.php --filter test_wp_upload_bits_should_support_stream_wrapper_directories (fails locally because the local test DB host mysql is not reachable without the Docker test env)

#5 @arkaprabhachowdhury
4 weeks ago

Opened [PR #12261](https://github.com/WordPress/wordpress-develop/pull/12261) to address this ticket. Summary - preserve trailing slashes for stream-wrapper directories before inheriting file permissions - use the helper in upload handling and both image editor implementations - add strict stream-wrapper regression coverage for uploads plus nested GD and Imagick saves Testing - `php vendor/bin/phpcbf --standard=phpcs.xml.dist src/wp-includes/functions.php src/wp-admin/includes/file.php src/wp-includes/class-wp-image-editor-gd.php src/wp-includes/class-wp-image-editor-imagick.php tests/phpunit/in The PR includes focused regression coverage, and its validation details are recorded in the PR description.

I picked this up because the ticket describes a concrete core behavior or edge case that remains relevant in current WordPress. The proposed change is intentionally scoped to the ticket and is submitted here for code review, with the technical discussion remaining on this ticket.

Note: See TracTickets for help on using tickets.