[PATCH v2 27/28] fs/squashfs: sqfs_read: fragmented files are not supported

Richard Genoud richard.genoud at posteo.net
Tue May 11 15:04:20 CEST 2021


Hi all,

Le 08/05/2021 à 23:51, Simon Glass a écrit :
> Hi,
> 
> On Thu, 4 Feb 2021 at 15:32, João Marcos Costa <jmcosta944 at gmail.com> wrote:
>>
>> Em qua., 27 de jan. de 2021 às 12:15, Simon Glass <sjg at chromium.org> escreveu:
>>>
>>> Hi Joao,
>>
>> Hello!
>>>
>>> This test works the first time I run it but fails the second time,
>>> since the directory already exists. This makes it necessary to disable
>>> the test for development.
>>>
>>> It also uses the wrong quoting style - we have settled on a single
>>> quote by default in U-Boot.
>>>
>>> Finally, the tests and some functions need comments about what they do
>>> and what the arguments are.
>>>
>>> Please can you take a look?
>>
>> Absolutely. Excuse me for such a late reply.
> 
> Any word on this please? Have you been able to repeat this?
Yes, for me, reading fragmented files doesn't work.
The test "test_sqfs_load" is OK because it only tests the file length not its content.

I've written a patch to check if the file is corrupted or not, and it fails :
./test/py/test.py --bd sandbox --build -k test_sqfs_load -v
[...]
AssertionError: assert not 'ERROR' in 'crc32 for 01000000 ... 010013eb ==> df8e6fe2 != d1522690 ** ERROR **'
[...]

Here's the patch onto v2021.07-rc2 :
----------8<--------
Subject: [PATCH] test/py: SquashFS: Check if loaded file is corrupted

After loading the file in memory, its content should be checked for
errors.

Signed-off-by: Richard Genoud <richard.genoud at posteo.net>
---
  test/py/tests/test_fs/test_squashfs/sqfs_common.py    | 5 ++++-
  test/py/tests/test_fs/test_squashfs/test_sqfs_load.py | 6 +++++-
  2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/test/py/tests/test_fs/test_squashfs/sqfs_common.py b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
index c96f92c1d8f..a7673c73762 100644
--- a/test/py/tests/test_fs/test_squashfs/sqfs_common.py
+++ b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
@@ -6,6 +6,7 @@ import os
  import random
  import string
  import subprocess
+import zlib

  def sqfs_get_random_letters(size):
      letters = []
@@ -19,12 +20,14 @@ def sqfs_generate_file(path, size):
      file = open(path, "w")
      file.write(content)
      file.close()
+    return zlib.crc32(content.encode())

  class Compression:
      def __init__(self, name, files, sizes, block_size = 4096):
          self.name = name
          self.files = files
          self.sizes = sizes
+        self.crc = []
          self.mksquashfs_opts = " -b " + str(block_size) + " -comp " + self.name

      def add_opt(self, opt):
@@ -34,7 +37,7 @@ class Compression:
          src = os.path.join(build_dir, "sqfs_src/")
          os.mkdir(src)
          for (f, s) in zip(self.files, self.sizes):
-            sqfs_generate_file(src + f, s)
+            self.crc.append(sqfs_generate_file(src + f, s))

          # the symbolic link always targets the first file
          os.symlink(self.files[0], src + "sym")
diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
index 9e900623846..2ab4660036e 100644
--- a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
+++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
@@ -4,6 +4,7 @@

  import os
  import pytest
+import zlib
  from sqfs_common import *

  @pytest.mark.boardspec('sandbox')
@@ -14,6 +15,7 @@ from sqfs_common import *
  def test_sqfs_load(u_boot_console):
      build_dir = u_boot_console.config.build_dir
      command = "sqfsload host 0 $kernel_addr_r "
+    sum_command = "crc32 -v $kernel_addr_r $filesize "

      for opt in comp_opts:
          # generate and load the squashfs image
@@ -30,10 +32,12 @@ def test_sqfs_load(u_boot_console):
          output = u_boot_console.run_command(command + "xxx")
          assert "File not found." in output

-        for (f, s) in zip(opt.files, opt.sizes):
+        for (f, s, c) in zip(opt.files, opt.sizes, opt.crc):
              try:
                  output = u_boot_console.run_command(command + f)
                  assert str(s) in output
+                output = u_boot_console.run_command(sum_command + format(c, '08x'))
+                assert not 'ERROR' in output
              except:
                  assert False
                  opt.cleanup(build_dir)
-- 
2.20.1


More information about the U-Boot mailing list