File Commander inefficiencies in RAR extraction

Issue #705 resolved
prl created an issue

In FileCommander.addons.unrar.checkPW() checks for whether the module has a valid password for the RAR file by running rar p on the archive and checking whether standard output contains the string "Corrupt file or wrong password."

There are three inefficiencies in this:

  • rar p extracts the whole archive to standard output, and the whole archive contents will be saved in memory in p.stdout. This uses an unnecessarily large amount of memory. The password validity can be tested by using rar t instead. This produces only one line of output for each file in the archive, along with any error messages if the password is incorrect.
  • The contents of p.stdout are searched using re.search('Corrupt file or wrong password.', stdlog, re.S). There is no need to use a regular expression for the search. The string that needs to be matched is literally "Corrupt file or wrong password.", so the test "Corrupt file or wrong password." in stdlog is more efficient and more accurately describes the match (because no wild character match on the last character is needed).
  • The contents of p.stdout are printed to the debug log, even if the password was incorrect and the output is the undecrypted archive contents. This is also an unnecessary amount of data, but is less unreasonable if rar t is used.

Replication steps

List the contents of a .rar file in File Commander and observe that the archive contents are written to the debug log by the password checking process.

Comments (1)

  1. Peter Urbanec

    Fix Bug #705: File Commander inefficiencies in RAR extraction

    Use "rar t" to test the password instead of "rar p", so that the whole archive isn't extracted into memory just to test the password.

    Use 'Corrupt file or wrong password.' in stdlog instead of an unnecessary regular expression search to test whether the password was correct.

    → <<cset 5b4cdb1f7ee2>>

  2. Log in to comment