mirror of
https://github.com/dgelessus/python-rsrcfork.git
synced 2024-11-12 10:06:52 +00:00
Fix overflow with empty resource files or empty resource type entries
This commit is contained in:
parent
d6de63e17b
commit
c207703c9f
@ -138,6 +138,11 @@ __ https://archive.fo/
|
||||
Changelog
|
||||
---------
|
||||
|
||||
Version 1.1.1
|
||||
`````````````
|
||||
|
||||
* Fixed overflow issue with empty resource files or empty resource type entries
|
||||
|
||||
Version 1.1.0
|
||||
`````````````
|
||||
|
||||
|
47
rsrcfork.py
47
rsrcfork.py
@ -345,14 +345,16 @@ class ResourceFile(collections.abc.Mapping):
|
||||
self._reference_counts: typing.MutableMapping[bytes, int] = collections.OrderedDict()
|
||||
|
||||
(type_list_length_m1,) = self._stream_unpack(STRUCT_RESOURCE_TYPE_LIST_HEADER)
|
||||
type_list_length = (type_list_length_m1 + 1) % 0x10000
|
||||
|
||||
for _ in range(type_list_length_m1 + 1):
|
||||
for _ in range(type_list_length):
|
||||
(
|
||||
resource_type,
|
||||
count_m1,
|
||||
reflist_offset,
|
||||
) = self._stream_unpack(STRUCT_RESOURCE_TYPE)
|
||||
self._reference_counts[resource_type] = count_m1 + 1
|
||||
count = (count_m1 + 1) % 0x10000
|
||||
self._reference_counts[resource_type] = count
|
||||
|
||||
def _read_all_references(self):
|
||||
"""Read all resource references, starting at the current stream position."""
|
||||
@ -745,25 +747,28 @@ def main(args: typing.Sequence[str]):
|
||||
else:
|
||||
print("No file attributes")
|
||||
|
||||
print(f"{len(rf)} resource types:")
|
||||
for typecode, resources in rf.items():
|
||||
restype = _bytes_escape(typecode, quote="'")
|
||||
print(f"'{restype}': {len(resources)} resources:")
|
||||
for resid, res in rf[typecode].items():
|
||||
if res.name is None:
|
||||
name = "unnamed"
|
||||
else:
|
||||
name = _bytes_escape(res.name, quote='"')
|
||||
name = f'name "{name}"'
|
||||
|
||||
attrs = _decompose_flags(res.attributes)
|
||||
if attrs:
|
||||
attrdesc = " | ".join(attr.name for attr in attrs)
|
||||
else:
|
||||
attrdesc = "no attributes"
|
||||
|
||||
print(f"({resid}), {name}, {attrdesc}, {len(res.data)} bytes")
|
||||
print()
|
||||
if len(rf) > 0:
|
||||
print(f"{len(rf)} resource types:")
|
||||
for typecode, resources in rf.items():
|
||||
restype = _bytes_escape(typecode, quote="'")
|
||||
print(f"'{restype}': {len(resources)} resources:")
|
||||
for resid, res in rf[typecode].items():
|
||||
if res.name is None:
|
||||
name = "unnamed"
|
||||
else:
|
||||
name = _bytes_escape(res.name, quote='"')
|
||||
name = f'name "{name}"'
|
||||
|
||||
attrs = _decompose_flags(res.attributes)
|
||||
if attrs:
|
||||
attrdesc = " | ".join(attr.name for attr in attrs)
|
||||
else:
|
||||
attrdesc = "no attributes"
|
||||
|
||||
print(f"({resid}), {name}, {attrdesc}, {len(res.data)} bytes")
|
||||
print()
|
||||
else:
|
||||
print("No resource types (empty resource file)")
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user