Repository navigation
Logo upload: never replace a file already in the media folder - #1103
Merged
Merged
Conversation
The logo upload wrote into the media root, which every store shares, with FileMode.OpenOrCreate. A file with the same name, such as another store's logo, was overwritten, and since the mode does not truncate, a shorter upload left the end of the old file behind and corrupted the image. The store panel reaches the same action. An upload whose name is taken is now saved under the next free name (logo-1.png, logo-2.png, ...) with FileMode.CreateNew, and that name is returned to the settings form. The two identical branches of the action are merged.
…first Looking for a free name and creating the file were two steps, so two uploads of the same name at once could both pick it; the second then failed, and its error message, which held the server's physical path, went back to the browser. The upload now tries CreateNew on each name in turn and takes the first that succeeds. Any other failure is left to the application's error handling, so no exception text reaches the response.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BasePictureController.AsyncLogoUpload(admin and store panels) wrote the logo into the media root, which every store shares, withFileMode.OpenOrCreate. An upload with an existing name, such as another store'slogo.png, overwrote that file. The mode does not truncate, so a shorter upload left the end of the old file behind and corrupted the image.Changes
logo-1.png,logo-2.png, ...) withFileMode.CreateNew; the returnedimageUrlcarries that name, which the settings form stores.Notes
Tests
BasePictureControllerTests.AsyncLogoUpload_NameTaken_KeepsTheExistingFile_AndSavesUnderAFreeName(new, on a temporary folder).Grand.Web.Admin.Tests(2110) pass;Grand.Web.Storebuilds.Review follow-up
CreateNewis tried on each name in turn and anIOExceptionon a name that exists moves to the next one, so two uploads of the same name at once both succeed.catchthat returned the exception message (with the server's physical path) to the browser is gone; any other failure is left to the application's error handling.Grand.Web.Admin.Tests(2110) pass.