Fall back to the Python strings when the system tool refuses a file - #5908
Open
arpitjain099 wants to merge 1 commit into
Open
Fall back to the Python strings when the system tool refuses a file#5908arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5907.
parse_stringscalledsubprocess.check_output(["strings", ...])with no failure handling, so a non-zero exit from the system tool raisedCalledProcessErrorout of the scan.Strings, the pure-Python implementation sitting directly above it, reads bytes and does not care what container format the file claims to be, so the fallback was already there and simply was not reached.I reproduced this on macOS rather than taking it on trust. A real class file,
JREProperties.classfrom a LibreOffice install, gives the reported error verbatim:and
parse_stringson it raisedCalledProcessErrorbefore this change and now returns 727 characters, includingjava/lang/Objectandjava/lang/System./bin/lsstill goes down the fast path and returns the same 1424 characters either way, so the system tool is still doing the work where it can.One thing beyond the report.
check_outputinherits stderr, so a jar full of class files printed oneerror: ... fat file:line per entry straight to the console. stderr is captured into the exception now and logged at debug, which keeps the diagnostic without the noise.Only a non-zero exit is absorbed.
OSErrorstill propagates, since a tool that cannot be run at all is a different problem from one that has looked at the file and declined it, and quietly swallowing that would hide a broken environment. There is a test for that.Three tests in
test/test_strings.py, all against a generated class file so nothing binary is added to the repo: the fallback path, a control that the system tool is still used when it exits 0, and theOSErrorcase. The first fails on the current code with theCalledProcessError.The two pre-existing
TestStringscases fail here before and after this branch, because they compare against the systemstringsand BSD output differs from binutils.ruff checkandruff format --checkare clean.