Fix crashes that could occur when detecting file mimetypes.

Review Request #14229 — Created Nov. 5, 2024 and submitted

Information

RBTools
release-5.x

Reviewers

This change mirrors a similar fix that we recently did for Review Board.
This fixes two issues with RBTools' MIME-type detection:

  1. Some versions of Python break if you try to close an already-closed
    pipe, and this had happened on one customer's machine. file may
    close the input stream once it's read enough data to make a
    determination, and our attempt to close would then fail.

  2. Errors executing or communicating with file would crash.

Ran unit tests.

Summary ID
Fix crashes that could occur when detecting file mimetypes.
This change mirrors a similar fix that we recently did for Review Board. This fixes two issues with RBTools' MIME-type detection: 1. Some versions of Python break if you try to close an already-closed pipe, and this had happened on one customer's machine. `file` may close the input stream once it's read enough data to make a determination, and our attempt to close would then fail. 3. Errors executing or communicating with `file` would crash, and even if caught higher up it'd leave the uploaded file truncated (the file pointer wouldn't be at 0). Testing Done: Ran unit tests.
8194c13c7aa42077a8f71dbf57930a267a6d15b3
david
maubin
  1. Ship It!
  2. 
      
chipx86
  1. Ship It!
  2. 
      
david
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.x (bc2d7a7)