Skip to content

Fix incorrect ISO metadata being written after shrinking#142

Open
Enzime wants to merge 2 commits intoclalancette:masterfrom
Enzime:push-llsuwyrpzqrm
Open

Fix incorrect ISO metadata being written after shrinking#142
Enzime wants to merge 2 commits intoclalancette:masterfrom
Enzime:push-llsuwyrpzqrm

Conversation

@Enzime
Copy link
Copy Markdown

@Enzime Enzime commented Feb 25, 2026

When I try to add a new file into a Windows 11 ISO using the following script:

import pycdlib

iso = pycdlib.PyCdlib()
iso.open('/Users/enzime/Downloads/26100.4349.250607-1500.ge_release_svc_refresh_CLIENTCONSUMER_RET_A64FRE_en-us.iso')
iso.add_file('/Users/enzime/Downloads/autounattend.xml', udf_path='/autounattend.xml')
iso.write('/Users/enzime/Downloads/Win11_unattended.iso')
iso.close()

iso = pycdlib.PyCdlib()
iso.open('/Users/enzime/Downloads/Win11_unattended.iso')

# Check UDF root for autounattend.xml
for child in iso.list_children(udf_path='/'):
    if child is None:
        continue
    if child.is_dot() or child.is_dotdot():
        continue
    name = child.file_identifier().decode('utf-8', errors='replace')
    print(name)

iso.close()

print('Done')

I would get the following error:

Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "/nix/store/187j0l8n5f1vwh85pq8fc78z5jqqf9ha-python3-3.13.11-env/lib/python3.13/site-packages/pycdlib/pycdlib.py", line 4066, in open
    self._open_fp(fp)
    ~~~~~~~~~~~~~^^^^
  File "/nix/store/187j0l8n5f1vwh85pq8fc78z5jqqf9ha-python3-3.13.11-env/lib/python3.13/site-packages/pycdlib/pycdlib.py", line 2319, in _open_fp
    self._parse_udf_descriptors()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/nix/store/187j0l8n5f1vwh85pq8fc78z5jqqf9ha-python3-3.13.11-env/lib/python3.13/site-packages/pycdlib/pycdlib.py", line 2017, in _parse_udf_descriptors
    raise pycdlibexception.PyCdlibInvalidISO('Expected at least 2 UDF Anchors')
pycdlib.pycdlibexception.PyCdlibInvalidISO: Expected at least 2 UDF Anchors

With this PR, the output ISO can be successfully opened and read:

boot
boot.catalog
bootmgr.efi
efi
setup.exe
sources
support
autounattend.xml
Done

When an existing ISO is opened, modified, and written back, the
reshuffled layout can be more compact than the original. This causes
the parser to miss the second UDF anchor on re-open.
_reshuffle_extents() packs extents sequentially, so when an existing
ISO is opened and modified, the reshuffled layout can be more compact
than what pvd.space_size reflects. The second UDF anchor was placed
at current_extent but the ISO was padded to pvd.space_size, leaving
the anchor at a location none of the five parser probe points would
check. Set pvd.space_size to current_extent + 1 so the anchor is
always at the last extent.
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

Successfully merging this pull request may close these issues.

1 participant