Skip to content

Return a bool from is_driver() and is_exe() again - #646

Merged
j-t-1 merged 2 commits into
erocarrera:masterfrom
HuzaifaChaudary:fix/is-driver-bool
Nov 5, 2026
Merged

j-t-1 merged 2 commits into
erocarrera:masterfrom
HuzaifaChaudary:fix/is-driver-bool

Conversation

@HuzaifaChaudary

Copy link
Copy Markdown
Contributor

#592 turned the if ... return True / return False at the end of is_driver() and is_exe() into one return a and b . the first operand is a set in is_driver() and an int in is_exe() , so when it is empty the function returns it , set() or 0 , instead of False :

>>> pe = pefile.PE("cmd.exe")
>>> pe.is_driver()
set()
>>> json.dumps({"is_driver": pe.is_driver()})
TypeError: Object of type set is not JSON serializable

so pe.is_driver() is False is no longer true for most files . v2024.8.26 still has the old code , so this is not in a release yet .

the fix wraps the first operand in bool() , the same way #607 did for has_dynamic_relocs() . over the 356 files in pefile-tests every result is a bool now and none changes its truth value . the new test fails before each change , with set() is not False and 0 is not False .

since erocarrera#592 the last line returns the set of matching section names and ( ... ) , so a file with no PAGE section gets set() back instead of False . pe.is_driver() is False is no longer true for most files , and json.dumps() of the result raises TypeError . this is not in a release yet , v2024.8.26 still has the if and return False .

wrapping the set in bool() , the same way erocarrera#607 did for has_dynamic_relocs() , puts it back . over the 356 files in pefile-tests every result is a bool now , and none changes its truth value . the new test fails before the change with set() is not False .
the same change in erocarrera#592 made is_exe() return the result of EXE_flag & Characteristics when that is 0 , so a file without IMAGE_FILE_EXECUTABLE_IMAGE gets 0 back instead of False . bool() around it , and the test clears the flag on cmd.exe , which fails before the change with 0 is not False .
Copilot AI balanced review requested due to automatic review settings November 3, 2026 13:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@j-t-1
j-t-1 merged commit 40c7a73 into erocarrera:master Nov 5, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants