Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find file to scan! Error When File Name Contains Multiple Spaces #125

Closed
thelaughinglama opened this issue Jul 14, 2024 · 3 comments · Fixed by #130
Closed

Could not find file to scan! Error When File Name Contains Multiple Spaces #125

thelaughinglama opened this issue Jul 14, 2024 · 3 comments · Fixed by #130
Assignees
Labels

Comments

@thelaughinglama
Copy link

I got an issue while checking if a file was infected. The problem arises when the file name contains multiple consecutive spaces. The current implementation alters the input file path by replacing consecutive spaces, leading to a "Could not find file to scan!" error during the scan.

Steps to Reproduce:
Attempt to scan a file with a name containing multiple consecutive spaces (e.g., "myfile name.txt").
The scan fails with a "Could not find file to scan!" error.

Expected Behavior:
The SDK should correctly handle file names with multiple consecutive spaces without altering the original file path, ensuring the file can be found and scanned.

Code snippet for reference

isInfected(file = '', cb) {
....................
    return new Promise(async (resolve, reject) => {
        // Original line causing the issue:
         file = file.trim().replace(/\s+/g, ' ');
............................
    });
}

There are a couple of ways to go about it.

  • We can correct the error message if the incoming file path after .trim() is not the same as after replacing multiple spaces.
  • We escape the spaces and do not alter the user input apart from trimming.

I went through the commit history for this line file = file.trim().replace(/\s+/g, ' '); and saw that we went from

  • just trimming the file path ->
  • trimming file path and escaping the path spaces ->
  • trimming file path and replacing multi-spaces with single-space

More information on this change would be really helpful.

@kylefarris kylefarris self-assigned this Jul 22, 2024
@kylefarris kylefarris added the bug label Jul 22, 2024
@kylefarris
Copy link
Owner

Thanks for the very thorough bug report @thelaughinglama . I'd have to go back and look at the commits where that line was changed to make sure there change wasn't made for a very good reason.

@kylefarris
Copy link
Owner

It looks like in the past, it was escaping spaces (but that was only really valid for the local_scan method which was all that existed in the beginning). It was presumably removed due to issues with scanning over sockets. But instead of just moving that string replacement to the local_scan section, that part was just naively modified to remove all multiple space characters to a single space which really has no value.

I'm going to patch this issue and write some tests. I will let you know once the version with the patch is released.

@kylefarris
Copy link
Owner

The patch has been applied in v2.2.3!

Thanks for the bug report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants