Skip to content

Commit

Permalink
Merge pull request #852 from onekey-sec/fix-ubi-seek-error
Browse files Browse the repository at this point in the history
fix(ubi): add exception handler for SeekError
  • Loading branch information
qkaiser authored Jun 6, 2024
2 parents 76e855c + 9143144 commit fde468c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 4 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
10 changes: 6 additions & 4 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 @@ -81,7 +81,7 @@ class UBIFSHandler(StructHandler):
"""
HEADER_STRUCT = "ubifs_sb_node_t"

EXTRACTOR = Command("ubireader_extract_files", "{inpath}", "-o", "{outdir}")
EXTRACTOR = Command("ubireader_extract_files", "{inpath}", "-w", "-o", "{outdir}")

def calculate_chunk(self, file: File, start_offset: int) -> Optional[ValidChunk]:
endian = get_endian(file, self._BIG_ENDIAN_MAGIC)
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 fde468c

Please sign in to comment.