Skip to content

fix(fileutil): handle decoding errors when inspecting profile files - #183

Open
reginaldalfret wants to merge 1 commit into
Netflix:masterfrom
reginaldalfret:netflix/issue-182-unreadable-profile-file-decode-error
Open

reginaldalfret wants to merge 1 commit into
Netflix:masterfrom
reginaldalfret:netflix/issue-182-unreadable-profile-file-decode-error

Conversation

@reginaldalfret

Copy link
Copy Markdown

Summary

Fixes an issue where _is_perf_file in fileutil.py raises an unhandled UnicodeDecodeError (or IOError) when reading files containing invalid UTF-8 bytes or corrupted data in PROFILE_DIR.

Problem

_is_perf_file iterates over file lines without catching decoding exceptions. When an unreadable or non-UTF8 file is present in PROFILE_DIR, UnicodeDecodeError propagates up through get_profile_type, causing the home page request to fail. Furthermore, the file handle was not guaranteed to be closed when exceptions occurred.

Solution

Safeguard the line-reading loop in _is_perf_file with a try...except...finally block. Catch any Exception and return False, ensuring the file stream is always cleanly closed in finally.

Testing

  • Added unit test test_is_perf_file_unreadable_bytes in tests/test_fileutil.py.
  • Verified test passes via pytest tests/test_fileutil.py.

Fixes #182

Fixes Netflix#182

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
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.

UnicodeDecodeError exception is raised when an unreadable file is in profile dir

1 participant