Repository navigation
[security] Implement tarfile-ignore-zeros-true - #28680
Conversation
|
12b644a to
e2eb335
Compare
ntBre
left a comment
There was a problem hiding this comment.
Thanks for looking into this. I had one question about the covered APIs and a question about the rule code.
Could you say how you chose the linter and rule code for this rule? I don't see this in the list of upstream codes, so I don't think we should useS203 here. Given our new categories, I think we could just make this a security rule (as you've already done) without assigning a code at all, like this rule:
ruff/crates/ruff_linter/src/codes.rs
Lines 1371 to 1372 in 348d2dc
| tarfile.TarFile.taropen("archive.tar", ignore_zeros=True) # error: [tarfile-ignore-zeros-true] | ||
| tarfile.TarFile.gzopen("archive.tar.gz", ignore_zeros=True) # error: [tarfile-ignore-zeros-true] | ||
| tarfile.TarFile.bz2open("archive.tar.bz2", ignore_zeros=True) # error: [tarfile-ignore-zeros-true] | ||
| tarfile.TarFile.xzopen("archive.tar.xz", ignore_zeros=True) # error: [tarfile-ignore-zeros-true] | ||
| tarfile.TarFile.zstopen("archive.tar.zst", ignore_zeros=True) # error: [tarfile-ignore-zeros-true] |
There was a problem hiding this comment.
Are these documented somewhere? I don't see them in the docs.
There was a problem hiding this comment.
They aren't. Those class methods exist in CPython and typeshed, but the tarfile docs don't cover them, so I've removed them from the rule and the tests. The rule now checks tarfile.open, TarFile.open, and the TarFile constructor, which matches the documented API and #27310.
|
@ntBre done as asked. |
flake8-bandit] Implement tarfile-ignore-zeros-true (S203)security] Implement tarfile-ignore-zeros-true
ntBre
left a comment
There was a problem hiding this comment.
Thank you! I took care of the merge conflict and added the rule to the call_with_qualified_name runner added today.
Summary
Adds the preview rule
tarfile-ignore-zeros-truefor statically truthyignore_zerosintarfileopeners. This setting skips empty and invalid blocks, so an archive may yield members that a parser stopping at those blocks would not see. The rule coverstarfile.open,TarFile(...), andTarFileopening class methods.Closes #27310
Test Plan
The new mdtest covers flagged and unflagged calls. The targeted mdtest passes.