Skip to content

Commit

Permalink
fix(ubi): add exception handler for SeekError
Browse files Browse the repository at this point in the history
Truncated UBI images can lead to SeekError being raised. We now handle
that situation gracefully.
  • Loading branch information
Mücahid KIR committed Jun 6, 2024
1 parent 76e855c commit 2e3425f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 3 deletions.
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
8 changes: 5 additions & 3 deletions unblob/handlers/filesystem/ubi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from unblob.extractors import Command

from ...file_utils import InvalidInputFormat, get_endian, iterate_patterns
from ...file_utils import InvalidInputFormat, SeekError, get_endian, iterate_patterns
from ...iter_utils import get_intervals
from ...models import File, Handler, HexString, StructHandler, ValidChunk

Expand Down Expand Up @@ -137,8 +137,10 @@ def _walk_ubi(self, file: File, peb_size: int) -> int:
first_bytes = file.read(len(self._UBI_EC_HEADER))
if first_bytes == b"" or first_bytes != self._UBI_EC_HEADER:
break
file.seek(offset + peb_size)

try:
file.seek(offset + peb_size)
except SeekError:
break
return offset

def calculate_chunk(self, file: File, start_offset: int) -> Optional[ValidChunk]:
Expand Down

0 comments on commit 2e3425f

Please sign in to comment.