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

Find out if iso file is truncated #126

Open
Dobatymo opened this issue Aug 14, 2024 · 0 comments
Open

Find out if iso file is truncated #126

Dobatymo opened this issue Aug 14, 2024 · 0 comments

Comments

@Dobatymo
Copy link

Dobatymo commented Aug 14, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant