Skip to content

Commit

Permalink
fix(FileSystem): relax .problems attribute type
Browse files Browse the repository at this point in the history
List[Report] and List[ExtractionProblem] are not compatible in general
due to mutability of the list could cause a non-ExtractionProblem Report
to appear in the FileSystem.problems.

However we do not expect to do anything with the FileSystem.problems
other than collecting them, so the specialized type is not really
important.
What we do lose is explicitly preventing the aliasing problem, whose
risk is considered very low.

In the end .problems can be passed in directly in ExtractResult,
without making an explicit copy in every case, just to get the type
checker happy.
  • Loading branch information
e3krisztian committed Aug 30, 2023
1 parent e5e923a commit 95dbbc7
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion unblob/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ExtractionProblem,
LinkExtractionProblem,
PathTraversalProblem,
Report,
SpecialFileExtractionProblem,
)

Expand Down Expand Up @@ -436,7 +437,7 @@ class FileSystem:
this is how symlinks work.
"""

problems: List[ExtractionProblem]
problems: List[Report]

def __init__(self, root: Path):
self.root = root.resolve()
Expand Down
2 changes: 1 addition & 1 deletion unblob/handlers/archive/hp/ipkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def extract(self, inpath: Path, outdir: Path):
for carve_path, start_offset, size in entries:
fs.carve(carve_path, file, start_offset, size)

return ExtractResult(reports=list(fs.problems))
return ExtractResult(reports=fs.problems)


class HPIPKGHandler(StructHandler):
Expand Down
2 changes: 1 addition & 1 deletion unblob/handlers/archive/xiaomi/hdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def extract(self, inpath: Path, outdir: Path):
with File.from_path(inpath) as file:
for output_path, start_offset, size in self.parse(file):
fs.carve(output_path, file, start_offset, size)
return ExtractResult(reports=list(fs.problems))
return ExtractResult(reports=fs.problems)

def parse(self, file: File) -> Iterable[Tuple[Path, int, int]]:
header = self._struct_parser.parse(self.header_struct, file, Endian.LITTLE)
Expand Down
2 changes: 1 addition & 1 deletion unblob/handlers/filesystem/romfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def extract(self, inpath: Path, outdir: Path):
header.validate()
header.recursive_walk(header.header_end_offset, None)
header.dump_fs()
return ExtractResult(reports=list(fs.problems))
return ExtractResult(reports=fs.problems)


class RomFSFSHandler(StructHandler):
Expand Down
2 changes: 1 addition & 1 deletion unblob/handlers/filesystem/yaffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def extract(self, inpath: Path, outdir: Path):
parser.parse(store=True)
fs = FileSystem(outdir)
parser.extract(fs)
return ExtractResult(reports=list(fs.problems))
return ExtractResult(reports=fs.problems)


class YAFFSHandler(Handler):
Expand Down

0 comments on commit 95dbbc7

Please sign in to comment.