Skip to content

Commit 9f0146b

Browse files
authored
Merge pull request #18 from desultory/dev
fix inodes >0xFFFFFFFF breaking headers
2 parents ca38a5d + 7cd4ae5 commit 9f0146b

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pycpio"
7-
version = "1.5.4"
7+
version = "1.5.5"
88

99
authors = [
1010
{ name="Desultory", email="[email protected]" },

src/pycpio/header/cpioheader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __setattr__(self, key, value):
6262
If the filesize changes, log a warning.
6363
6464
Check the mode and set the mode_type and permissions attributes accordingly.
65+
Check that the inode is < 0xFFFFFFFF, if not, set to 0 and log a warning.
66+
When used in an archive, the inode will be set to a unique value.
6567
If setting the name, add a null byte to the end and set the namesize attribute.
6668
"""
6769
if key in ["uid", "gid"] and not isinstance(value, bytes):
@@ -97,6 +99,10 @@ def __setattr__(self, key, value):
9799
elif key == "filesize" and value == b"00000000":
98100
if getattr(self, "filesize", b"00000000") != b"00000000":
99101
self.logger.warning("[%s] Setting filesize to 0" % self.name)
102+
elif key == "ino":
103+
if int(value, 16) > 0xFFFFFFFF:
104+
self.logger.warning("Inode too large, setting to 0: %s" % value)
105+
value = b"00000000"
100106

101107
super().__setattr__(key, value)
102108

tests/test_cpio.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from pycpio import PyCPIO
99
from pycpio.header import CPIOHeader
10+
from pycpio.cpio import CPIOData
1011
from zenlib.logging import loggify
1112

1213
from cpio_test_headers import newc_test_headers, build_newc_header
@@ -145,5 +146,11 @@ def test_invalid_symlink_target(self):
145146
test_symlink.symlink_to('/a/totally/nonexistent/path')
146147
self.cpio.append_recursive(self.workdir.name)
147148

149+
def test_large_inode(self):
150+
""" Tests handling of inode numbers larger than 0xFFFFFFFF """
151+
entry = CPIOData.create_entry('large_inode_test', inode=0x1FFFFFFFF, logger=self.logger)
152+
# Should be reset to 0
153+
self.assertEqual(entry.header.ino, b'00000000')
154+
148155
if __name__ == '__main__':
149156
main()

0 commit comments

Comments
 (0)