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

Wrong File handling in OTXQuery Analyzer #313

Closed
sevdog opened this issue Jul 26, 2018 · 1 comment
Closed

Wrong File handling in OTXQuery Analyzer #313

sevdog opened this issue Jul 26, 2018 · 1 comment
Assignees
Labels
category:enhancement Issue is related to an existing feature to improve scope:analyzer Issue is analyzer related
Milestone

Comments

@sevdog
Copy link

sevdog commented Jul 26, 2018

Wrong File handling in OTXQuery Analyzer

Request Type

Bug

Work Environment

N/A

Description

In OTXQuery otxquery module the file is mishandled during hash calculation, this may cause various problems:

hash = hashlib.sha256(open(filepath, 'r').read()).hexdigest();

Problems are:

  1. file handler is never closed
  2. for hash calculation open mode should be binary (rb)
  3. if the file is big this operation will be very slow and will use a lot of memory

Possible Solutions

  1. The file should be opened using a with statement (aka context manager), as also suggested by python language guidelines

It is good practice to use the with keyword when dealing with file objects

  1. The file should be opened in binary mode: rb
  2. Reads should be performed per chunk as suggested in this post on SO and also like [django does][(https://docs.djangoproject.com/en/2.0/_modules/django/core/files/base/#File.chunks)
  3. Remove trailing semicolon (;)
@sevdog sevdog changed the title Wrong File handling in OTXQuery Analyser Wrong File handling in OTXQuery Analyzer Jul 26, 2018
@3c7 3c7 added category:enhancement Issue is related to an existing feature to improve help wanted scope:analyzer Issue is analyzer related good first issue labels Aug 2, 2018
3c7 added a commit that referenced this issue Jan 22, 2019
@3c7 3c7 self-assigned this Jan 22, 2019
@3c7 3c7 added this to the 1.15.2 milestone Jan 22, 2019
@3c7
Copy link
Contributor

3c7 commented Jan 22, 2019

Thanks for reporting. Fixed in 1.15.2.

@3c7 3c7 closed this as completed Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:enhancement Issue is related to an existing feature to improve scope:analyzer Issue is analyzer related
Projects
None yet
Development

No branches or pull requests

2 participants