Fix crashes that could occur when detecting file mimetypes.

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

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.

Diff Revision 1 (Latest)

Commits

First Last Summary ID Author
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 Trowbridge
rbtools/utils/mimetypes.py
Loading...