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

Stops reading from out side of file bounds. #631

Merged
merged 1 commit into from
Jan 7, 2022
Merged
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
16 changes: 8 additions & 8 deletions asammdf/blocks/mdf_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def _read(self, mapped: bool = False) -> None:
# read file history
fh_addr = self.header["file_history_addr"]
while fh_addr:
if fh_addr > self.file_limit:
if (fh_addr + v4c.FH_BLOCK_SIZE) > self.file_limit:
logger.warning(
f"File history address {fh_addr:X} is outside the file size {self.file_limit}"
)
Expand All @@ -507,7 +507,7 @@ def _read(self, mapped: bool = False) -> None:
at_addr = self.header["first_attachment_addr"]
index = 0
while at_addr:
if at_addr > self.file_limit:
if (at_addr + v4c.AT_COMMON_SIZE) > self.file_limit:
logger.warning(
f"Attachment address {at_addr:X} is outside the file size {self.file_limit}"
)
Expand All @@ -522,7 +522,7 @@ def _read(self, mapped: bool = False) -> None:
dg_addr = self.header.first_dg_addr

while dg_addr:
if dg_addr > self.file_limit:
if (dg_addr + v4c.DG_BLOCK_SIZE) > self.file_limit:
logger.warning(
f"Data group address {dg_addr:X} is outside the file size {self.file_limit}"
)
Expand All @@ -539,7 +539,7 @@ def _read(self, mapped: bool = False) -> None:
cg_size = {}

while cg_addr:
if cg_addr > self.file_limit:
if (cg_addr + v4c.CG_BLOCK_SIZE) > self.file_limit:
logger.warning(
f"Channel group address {cg_addr:X} is outside the file size {self.file_limit}"
)
Expand Down Expand Up @@ -785,7 +785,7 @@ def _read(self, mapped: bool = False) -> None:
ev_map = {}
event_index = 0
while addr:
if addr > self.file_limit:
if (addr + v4c.COMMON_SIZE) > self.file_limit:
logger.warning(
f"Event address {addr:X} is outside the file size {self.file_limit}"
)
Expand Down Expand Up @@ -856,7 +856,7 @@ def _read_channels(
while ch_addr:
# read channel block and create channel object

if ch_addr > self.file_limit:
if (ch_addr + v4c.COMMON_SIZE) > self.file_limit:
logger.warning(
f"Channel address {ch_addr:X} is outside the file size {self.file_limit}"
)
Expand Down Expand Up @@ -936,7 +936,7 @@ def _read_channels(
ch_addr = next_ch_addr
continue
else:
if component_addr > self.file_limit:
if (component_addr + v4c.CC_ALG_BLOCK_SIZE) > self.file_limit:
logger.warning(
f"Channel component address {component_addr:X} is outside the file size {self.file_limit}"
)
Expand Down Expand Up @@ -1018,7 +1018,7 @@ def _read_channels(

if component_addr:

if component_addr > self.file_limit:
if (component_addr + 4) > self.file_limit:
logger.warning(
f"Channel component address {component_addr:X} is outside the file size {self.file_limit}"
)
Expand Down