- changed status to resolved
File Commander inefficiencies in RAR extraction
Issue #705
resolved
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 inp.stdout
. This uses an unnecessarily large amount of memory. The password validity can be tested by usingrar 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 usingre.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 ifrar 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)
-
- Log in to comment
Fix Bug
#705: File Commander inefficiencies in RAR extractionUse "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>>