Quality: Broad exception handling in fill_from_encoding#3771
Open
SlncTrZ wants to merge 1 commit into
Open
Conversation
The function fill_from_encoding catches a generic Exception when decoding bytes to string. This can mask various errors (e.g., MemoryError, KeyboardInterrupt) and makes debugging difficult. It should catch specific exceptions like UnicodeDecodeError. Affected files: __init__.py Signed-off-by: Dinh Truong (SlncTrZ) <46520299+SlncTrZ@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3771 +/- ##
=======================================
Coverage 97.62% 97.62%
=======================================
Files 55 55
Lines 10221 10221
Branches 1876 1876
=======================================
Hits 9978 9978
Misses 138 138
Partials 105 105 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
stefan6419846
requested changes
May 11, 2026
Collaborator
stefan6419846
left a comment
There was a problem hiding this comment.
Thanks for the PR. Could you please have a look at the test failures?
Additionally: Did you run into specific issues where we could add a test for as well, or this is a generic finding?
Author
|
Hi, this is a generic finding! But let me see what I can do with this
Best Regards
Trương Công Định
Mobile / WeChat / Skype: 0981684212
…On Mon, May 11, 2026 at 16:26 Stefan ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Thanks for the PR. Could you please have a look at the test failures?
Additionally: Did you run into specific issues where we could add a test
for as well, or this is a generic finding?
—
Reply to this email directly, view it on GitHub
<#3771 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALC5P22PSCNUEBNXWXW463D42GMFRAVCNFSM6AAAAACYYLYQ26VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DENRSGI2TONZQGE>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
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.
Summary
Quality: Broad exception handling in fill_from_encoding
Problem
Severity:
Low| File:pypdf/_codecs/__init__.py:L10The function fill_from_encoding catches a generic Exception when decoding bytes to string. This can mask various errors (e.g., MemoryError, KeyboardInterrupt) and makes debugging difficult. It should catch specific exceptions like UnicodeDecodeError.
Solution
Replace
except Exception:withexcept UnicodeDecodeError:to handle only expected decoding failures.Changes
pypdf/_codecs/__init__.py(modified)Testing