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

Raise an exception when sector cannot be converted to array #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions olefile/olefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,10 @@ def sect2array(self, sect):
swapping bytes on big endian CPUs such as PowerPC (old Macs)
"""
# TODO: make this a static function
if len(sect) % array.array(UINT32).itemsize != 0:
# to convert to an array of UINT32s we need to have a bytes string
# with a length that is a multiple of the itemsize.
self._raise_defect(DEFECT_FATAL, 'incorrect sector size, cannot convert to array of 32bit unsigned integers')
a = array.array(UINT32, sect)
# if CPU is big endian, swap bytes:
if sys.byteorder == 'big':
Expand Down