Patch #35539

Race condition (possible filename collision) in Attachment.disk_filename

Added by Jens Krämer 4 months ago. Updated 2 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Attachments
Target version:5.0.0

Description

When two (or more) files with the same name are uploaded at the same time, it may happen that two or more of the resulting attachment records end up using the same disk file, resulting in data loss if the files actually differ in content. This was already previously mentioned in #34479-2 (but was unrelated to that issue and hence got "lost")

The problem is that Attachment.disk_filename finds a non-existant filename, but fails to "claim" this name in the file system while doing so. So nothing stops a parallel process to end up using the same name if it tries to do so before the first process actually creates the file.

This patch, extracted from Planio , instead tries to create a file directly, with the File::EXCL flag set, catches the error which means 'filename taken already' and retries until the file is created. This way, filenames are guaranteed to be unique by the underlying file system.

0001-ensure-unique-attachment-filenames.patch Magnifier (4.78 KB) Jens Krämer, 2021-07-07 07:20


Related issues

Related to Redmine - Patch #35720: Defect: Binmode specified twice Closed
Related to Redmine - Patch #35721: Unlink files after they're closed Closed

Associated revisions

Revision 21071
Added by Go MAEDA 3 months ago

Ensure unique attachment filenames (#35539).

Patch by Jens Krämer.

Revision 21193
Added by Go MAEDA 2 months ago

Fix that binmode specified twice (#35539, #35720).

Patch by Pavel Rosický.

Revision 21194
Added by Go MAEDA 2 months ago

Don't unlink files before closing them (#35539, #35721).

Patch by Pavel Rosický.

History

#1 Updated by Go MAEDA 4 months ago

  • Target version set to Candidate for next major release

#2 Updated by Go MAEDA 4 months ago

  • Target version changed from Candidate for next major release to 5.0.0

Setting the target version to 5.0.0.

#3 Updated by Go MAEDA 3 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patch. Thank you.

#4 Updated by Go MAEDA 3 months ago

  • Related to Patch #35720: Defect: Binmode specified twice added

#5 Updated by Go MAEDA 3 months ago

  • Related to Patch #35721: Unlink files after they're closed added

#6 Updated by Go MAEDA 3 months ago

  • Status changed from Closed to Reopened

Reopening this issue in order to handle #35720 and #35721.

#7 Updated by Go MAEDA 2 months ago

  • Status changed from Reopened to Closed

Go MAEDA wrote:

Reopening this issue in order to handle #35720 and #35721.

Committed the fixes in r21193 and r21194.

Also available in: Atom PDF