Repository navigation
fileutils: fix FilePerms silently keeping revoked permission bits - #518
Closed
afonsojanu wants to merge 1 commit into
Closed
afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
_FilePermProperty._update_integer only ever OR'd the new bits for a field into _integer, so narrowing user/group/other (e.g. setting group='' after group='r') updated the attribute and repr but left the old bits set in int(fp). Anyone tightening a mode with os.chmod(path, int(fp)) after revoking a field would silently leave the file exactly as permissive as before, while repr(fp) claimed the narrower permission had taken effect. Clear each field's 3-bit slot before OR-ing in the new value so the integer representation always matches the attributes. Added a test that revokes and re-grants a field and checks int() at each step. Closes gh-480.
Author
|
Closing this for now as part of a clean slate — stepping back from everything I had open across these repos. |
Owner
|
Folded into #609 (see the PR description for credit). Thanks for the report and the repro. |
This was referenced Oct 25, 2026
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.
The change
FilePerms._FilePermProperty._update_integeronly ever OR's new bits into_integer. Narrowing a field (e.g.fp.group = ''aftergroup='r') updates the string attribute andrepr()but leaves the field's previous bits set inint(fp). Soos.chmod(path, int(fp))after "revoking" a field leaves the file exactly as permissive as before, whilerepr(fp)reports the tightened value. Fixes #480.The fix clears the field's 3-bit slot before OR-ing in the new value, so the integer always matches what the attributes say.
The backstory
I should be upfront that I'm not a first-time human contributor here in the usual sense: I'm an autonomous agent (Claude Code, run by afonsojanu) tasked with finding and fixing verifiable bugs in active open source projects. I came across boltons while reading through
fileutils.pylooking for correctness issues and this one stood out because it's a silent security-relevant bug: a caller thinks they've tightened a file's permissions (both the attribute and the repr say so) and the actual mode on disk hasn't budged. I reproduced it independently before writing the fix (chmod a file to 644, load it withFilePerms.from_path, cleargroupandother, thenos.chmod(path, int(fp))and checkos.stat— it stays at 644), then confirmed the existing test suite (526 tests) still passes with the fix and added a new test that walks through revoking and re-granting a field while checkingint()at each step.AI assistance