diff --git a/pyproject.toml b/pyproject.toml index d21c106..7ff9b54 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pycpio" -version = "1.5.4" +version = "1.5.5" authors = [ { name="Desultory", email="dev@pyl.onl" }, diff --git a/src/pycpio/header/cpioheader.py b/src/pycpio/header/cpioheader.py index 7545a3f..c437f0d 100644 --- a/src/pycpio/header/cpioheader.py +++ b/src/pycpio/header/cpioheader.py @@ -62,6 +62,8 @@ def __setattr__(self, key, value): If the filesize changes, log a warning. Check the mode and set the mode_type and permissions attributes accordingly. + Check that the inode is < 0xFFFFFFFF, if not, set to 0 and log a warning. + When used in an archive, the inode will be set to a unique value. If setting the name, add a null byte to the end and set the namesize attribute. """ if key in ["uid", "gid"] and not isinstance(value, bytes): @@ -97,6 +99,10 @@ def __setattr__(self, key, value): elif key == "filesize" and value == b"00000000": if getattr(self, "filesize", b"00000000") != b"00000000": self.logger.warning("[%s] Setting filesize to 0" % self.name) + elif key == "ino": + if int(value, 16) > 0xFFFFFFFF: + self.logger.warning("Inode too large, setting to 0: %s" % value) + value = b"00000000" super().__setattr__(key, value) diff --git a/tests/test_cpio.py b/tests/test_cpio.py index 483f811..052ceed 100644 --- a/tests/test_cpio.py +++ b/tests/test_cpio.py @@ -7,6 +7,7 @@ from pycpio import PyCPIO from pycpio.header import CPIOHeader +from pycpio.cpio import CPIOData from zenlib.logging import loggify from cpio_test_headers import newc_test_headers, build_newc_header @@ -145,5 +146,11 @@ def test_invalid_symlink_target(self): test_symlink.symlink_to('/a/totally/nonexistent/path') self.cpio.append_recursive(self.workdir.name) + def test_large_inode(self): + """ Tests handling of inode numbers larger than 0xFFFFFFFF """ + entry = CPIOData.create_entry('large_inode_test', inode=0x1FFFFFFFF, logger=self.logger) + # Should be reset to 0 + self.assertEqual(entry.header.ino, b'00000000') + if __name__ == '__main__': main()