Skip to content

Conversation

@psrok1
Copy link

@psrok1 psrok1 commented Nov 18, 2025

Due to wrong usage of importlib.resources.as_file: password.txt is gathered by simple relative path instead of resolved package path.

Before patch (note that I'm intentionally in different CWD):

~$ python
Python 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sflock.config import iter_passwords
>>> list(iter_passwords())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/psrok1/sflock/venv/lib/python3.12/site-packages/sflock/config.py", line 16, in iter_passwords
    for line in passwd_file.read_text().splitlines():
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/pathlib.py", line 1029, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/pathlib.py", line 1015, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'sflock/data/password.txt'
>>> 

After patch:

~$ python
Python 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sflock.config import iter_passwords
>>> list(iter_passwords())
['infected', 'malware', 'password']
>>> 
KeyboardInterrupt
>>> 

@gemini-code-assist
Copy link

Summary of Changes

Hello @psrok1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where the iter_passwords function failed to locate its associated password.txt resource when the application was run from a directory other than its root. The fix involves a more robust method of accessing package data, ensuring that the necessary resource files are always correctly identified and loaded, thereby improving the stability and portability of the sflock configuration module.

Highlights

  • Fix FileNotFoundError: Resolved a FileNotFoundError that occurred when iter_passwords was called from a different current working directory, preventing the password.txt file from being located.
  • Improved Resource Loading: Updated the resource loading mechanism for password.txt to correctly use importlib.resources.files to resolve the package path, ensuring the file is found reliably regardless of the execution context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a FileNotFoundError when accessing package data by using importlib.resources.files. The approach is sound and resolves the issue of being dependent on the current working directory. I've added one suggestion to make the password iteration more robust by filtering out any empty or whitespace-only lines from the password file.

Comment on lines 16 to 17
for line in passwd_file.read_text().splitlines():
yield line.strip()

Choose a reason for hiding this comment

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

medium

The current implementation could yield empty strings if the password file contains empty lines or lines with only whitespace. It's good practice to explicitly filter these out to avoid attempting to use an empty password.

Suggested change
for line in passwd_file.read_text().splitlines():
yield line.strip()
for line in passwd_file.read_text().splitlines():
stripped = line.strip()
if stripped:
yield stripped

@doomedraven doomedraven merged commit 558620d into CAPESandbox:master Nov 18, 2025
4 checks passed
@doomedraven
Copy link
Collaborator

thank you

psrok1 added a commit to CERT-Polska/karton-archive-extractor that referenced this pull request Nov 18, 2025
Fixes: No such file and directory 'sflock/data/password.txt' (CAPESandbox/sflock#63)
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.

2 participants