Closed Bug 1744779 Opened 2 years ago Closed 2 years ago

Failing to download file due to missing filename sanitation

Categories

(Firefox :: Screenshots, defect, P2)

defect
Points:
2

Tracking

()

VERIFIED FIXED
98 Branch
Tracking Status
firefox97 --- wontfix
firefox98 --- fixed
firefox110 --- verified

People

(Reporter: TheOne, Assigned: enndeakin)

References

Details

(Whiteboard: [fidefe-quality-foundation])

Attachments

(1 file)

When trying to download a screenshot from a page whose title has certain non-allowed characters, saving on disk fails without any visual feedback.

STR:

  1. Go to https://addons.mozilla.org/he/firefox/addon/multi-account-containers/ .
  2. Use the Screenshots feature to a screenshot.
  3. Click "Download".

Expected result:
The downloaded screenshot should be on the disk.

Actual result:
The screenshot file isn't on the disk.

Additional information:

Thanks for filing this. I didn't find a dupe but I'm a little surprised we're just now finding this.

Severity: -- → S2
Priority: -- → P2
Whiteboard: [fidefe-quality-foundation]

I wonder if it would make sense to expose DownloadPaths.sanitize on the downloads extension API. Then this extension - and all the others - wouldn't have to guess what was ok and what was not.

(In reply to Sam Foster [:sfoster] (he/him) from comment #3)

I wonder if it would make sense to expose DownloadPaths.sanitize on the downloads extension API. Then this extension - and all the others - wouldn't have to guess what was ok and what was not.

We are working towards porting Screenshots to a browser component, where this question becomes moot, but in the meantime - and for other extensions - I'm interested in options and opinions here. Yes, I can just copy/paste the relevant bits into the Screenshots code for now and that might be most expedient for here and now.

(In reply to Sam Foster [:sfoster] (he/him) from comment #3)

I wonder if it would make sense to expose DownloadPaths.sanitize on the downloads extension API. Then this extension - and all the others - wouldn't have to guess what was ok and what was not.

Has there been any discussion of something like this, do you have your own thoughts :robwu?

Flags: needinfo?(rob)

Throwing an error for invalid file names is intentional, and also consistent with what Chrome does (Chrome is even stricter on the permitted file names (source)).

I don't see value in offering a new extension method to sanitize file paths, because there are hardly any extension APIs to operate on files / actual file names. If anything, a new optional option to automatically offer sanitization of file names would make more sense. But unless this is adopted by other browsers, extensions would still need to do error handling and include a fallback for sanitizing the file name.

Flags: needinfo?(rob)

(In reply to Rob Wu [:robwu] from comment #6)

I don't see value in offering a new extension method to sanitize file paths, because there are hardly any extension APIs to operate on files / actual file names. If anything, a new optional option to automatically offer sanitization of file names would make more sense. But unless this is adopted by other browsers, extensions would still need to do error handling and include a fallback for sanitizing the file name.

Ok that's useful context. For Screenshots, I'll just snag the important pieces from DownloadPaths.sanitize so we can generate filenames that we can be reasonably sure will work on the current OS, and pass the DownloadPaths.sanitize test.

Assignee: nobody → sfoster
Status: NEW → ASSIGNED
Assignee: sfoster → nobody
Status: ASSIGNED → NEW
Assignee: nobody → enndeakin
Status: NEW → ASSIGNED

Sam, the issue with bug 1748784 is a different issue. It is caused because the filename is too long for a linux filesystem which is limited to 255 bytes for a filename.

But in that bug, you suggested that you had a fix for the filename length. Is that a fix we could include here?

Flags: needinfo?(sfoster)

I think this was the important bit:

diff --git a/browser/extensions/screenshots/build/shot.js b/browser/extensions/screenshots/build/shot.js
--- a/browser/extensions/screenshots/build/shot.js
+++ b/browser/extensions/screenshots/build/shot.js
@@ -383,7 +383,7 @@ this.shot = (function() {
       const filenameDate = currentDateTime.substring(0, 10);
       const filenameTime = currentDateTime.substring(11, 19).replace(/:/g, "-");
       let clipFilename = `Screenshot ${filenameDate} at ${filenameTime} ${filenameTitle}`;
-      const clipFilenameBytesSize = clipFilename.length * 2; // JS STrings are UTF-16
+      const clipFilenameBytesSize = new Blob([clipFilename]).size; // Max size needs to be bytes not chars
       if (clipFilenameBytesSize > 251) {
         // 255 bytes (Usual filesystems max) - 4 for the ".png" file extension string
         const excedingchars = (clipFilenameBytesSize - 246) / 2; // 251 - 5 for ellipsis "[...]"
Flags: needinfo?(sfoster)
Attachment #9261590 - Attachment description: Bug 1744779, improve filename sanitization when selecting a filename for a screenshot, r=sfoster → Bug 1744779, improve filename sanitization when selecting a filename for a screenshot, and change the filename length cropping to account for 255-byte filename limit on linux, r=sfoster
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 98 Branch
See Also: → 1754008
Points: --- → 2

I have verified this issue using the latest Firefox Nightly 110.0a1 (Build ID: 20230103094636) on Linux Mint 20.2 x64 using the steps provided in the Description and I can confirm the following:

  • The downloaded screenshot is successfully saved on the disk.
Status: RESOLVED → VERIFIED
Regressions: 1858099
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: