From 4750bcfe857c5a0feda86b54f260a11a4e3222cd Mon Sep 17 00:00:00 2001 From: Shahriyar Jalayeri Date: Tue, 28 Jul 2026 08:55:40 +0200 Subject: test: squashfs: add directory table overflow regression test Add a Python test that lists a crafted SquashFS image whose directory table declares an oversized metadata-block count. Such an image must be rejected without corrupting the heap, which the test checks by confirming U-Boot is still responsive afterwards. Signed-off-by: Shahriyar Jalayeri Reviewed-by: Richard Genoud --- .../test_fs/test_squashfs/test_sqfs_overflow.py | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/py/tests/test_fs/test_squashfs/test_sqfs_overflow.py diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_overflow.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_overflow.py new file mode 100644 index 00000000000..df7f875a58f --- /dev/null +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_overflow.py @@ -0,0 +1,75 @@ +# SPDX-License-Identifier: GPL-2.0 +# Regression test for the SquashFS directory-table integer overflow. + +import os +import struct +import pytest + +# metadata block size (SQFS_METADATA_BLOCK_SIZE) and metadata header size +SQFS_METADATA_BLOCK_SIZE = 8192 +# metablks_count that makes metablks_count * SQFS_METADATA_BLOCK_SIZE wrap a +# 32-bit int back down to a tiny value: (2^19 + 1) * 8192 == 2^32 + 8192. +NR_METABLKS = (1 << 19) + 1 + +def make_overflow_image(path): + """Build a SquashFS image whose directory table inflates metablks_count so + that metablks_count * SQFS_METADATA_BLOCK_SIZE wraps a 32-bit int, then + writes one block of data one metadata block past the resulting buffer.""" + def metahdr(size): + # uncompressed metadata block header (bit 15 set) + return struct.pack('