Skip to content

Find out if iso file is truncated #126

@Dobatymo

Description

@Dobatymo

I was trying to write a script to verify the correctness of iso files. Most importantly to find out if they were truncated. My idea was to extract each file and compare with the expected file size.
However I think this line

new_record.inode.data_length = iso_file_length - extent_to_use * self.logical_block_size

prevents me from doing so as it "helpfully" "fixes" the filesize in exactly this case.
If I comment out this line it's working.

iso = PyCdlib()
try:
    iso.open(path)
    try:
        for basepath, dirlist, filelist in iso.walk(iso_path="/"):
            for filename in filelist:
                path = f"{basepath}/{filename}"
                record = iso.get_record(iso_path=path)
                if not record.is_symlink() and record.is_file():
                    with open(os.devnull, "wb") as fw:
                        iso.get_file_from_iso_fp(fw, iso_path=path)
                        if record.get_data_length() != fw.tell():
                            raise RuntimeError("truncated file")
    finally:
        iso.close()
except PyCdlibInvalidISO as e:
    raise RuntimeError("broken file")

Is there some way to achieve this without modifying the library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions