diff --git a/hachoir/parser/file_system/ext2.py b/hachoir/parser/file_system/ext2.py index bd607fb4..44db6485 100644 --- a/hachoir/parser/file_system/ext2.py +++ b/hachoir/parser/file_system/ext2.py @@ -201,10 +201,13 @@ class Inode(FieldSet): 7: "Reserved group descriptors", 8: "EXT3 journal" } - static_size = (68 + 15 * 4) * 8 def __init__(self, parent, name, index): FieldSet.__init__(self, parent, name, None) + inode_size = self["/superblock/inode_size"].value + if inode_size == 0: + inode_size = 128 + self._size = inode_size * 8 self.uniq_id = 1 + index def createDescription(self): @@ -751,7 +754,10 @@ def validate(self): return "Invalid magic number" if not (0 <= self["superblock/log_block_size"].value <= 2): return "Invalid (log) block size" - if self["superblock/inode_size"].value not in (0, 128): + blocksize = (1 << 10) << self["superblock/log_block_size"].value + acceptable_inode_sizes = (s for s in [0, 128, 256, 512, 1024, 2048, 4096] + if s <= blocksize) + if self["superblock/inode_size"].value not in acceptable_inode_sizes: return "Unsupported inode size" return True diff --git a/tests/files/bsize-1024-isize-1024.ext2 b/tests/files/bsize-1024-isize-1024.ext2 new file mode 100644 index 00000000..e920f6dd Binary files /dev/null and b/tests/files/bsize-1024-isize-1024.ext2 differ diff --git a/tests/files/bsize-2048-isize-512.ext2 b/tests/files/bsize-2048-isize-512.ext2 new file mode 100644 index 00000000..b1487a8d Binary files /dev/null and b/tests/files/bsize-2048-isize-512.ext2 differ diff --git a/tests/files/bsize-4096-isize-128.ext2 b/tests/files/bsize-4096-isize-128.ext2 new file mode 100644 index 00000000..d7ab5132 Binary files /dev/null and b/tests/files/bsize-4096-isize-128.ext2 differ diff --git a/tests/test_parser.py b/tests/test_parser.py index 11278b6e..7ef4c7d0 100755 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -348,6 +348,16 @@ def test_ext2_variety_inode_types(self): self.checkDesc(parser, "/group[0]/inode_table/inode[12]", "Inode 13: Symbolic link (-> XYZ), size=3 bytes, mode=lrwxrwxrwx") + def test_ext2_various_inode_sizes(self): + for bsize, isize in [(1024, 1024), (2048, 512), (4096, 128)]: + fname = "bsize-%d-isize-%d.ext2" % (bsize, isize) + parser = self.parse(fname) + self.checkValue(parser, "/superblock/inode_size", isize) + self.checkValue(parser, "/group[0]/inode_table/inode[11]/size", 6) + self.checkDesc(parser, "/group[0]/inode_table/inode[12]", + "Inode 13: Symbolic link (-> source), size=6 bytes, mode=lrwxrwxrwx") + self.checkValue(parser, "/group[0]/inode[11]block[0]", b"hello\n" + b'\0' * (bsize - 6)) + def test_bmp2(self): parser = self.parse("article01.bmp") self.checkDisplay(parser, "/header/red_mask", '0x00ff0000')