commit 88cfa0464dc86d088e0f8484bc15a279d83919e9
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Mon Apr 28 13:53:40 2025 +0200

    ext2fs: fix crash on ENOSPC
    
    54c0b9b9dbf7 ("ext2fs: Trap trying to access bogus data areas") added
    checks on the allocated block number, but did not take care of the
    out-of-space condition, which callers of ext2_new_block and
    ext2_alloc_block know to handle.

diff --git a/ext2fs/balloc.c b/ext2fs/balloc.c
index 231ab589..0957f19e 100644
--- a/ext2fs/balloc.c
+++ b/ext2fs/balloc.c
@@ -407,8 +407,9 @@ got_block:
   alloc_sync (0);
 
   /* Trap trying to allocate superblock, block group descriptor table, or beyond the end */
-  assert_backtrace (j >= group_desc_block_end
-		 && j < store->size >> log2_block_size);
+  assert_backtrace (j == 0 ||
+		    (j >= group_desc_block_end
+		     && j < store->size >> log2_block_size));
 
   return j;
 }
diff --git a/ext2fs/getblk.c b/ext2fs/getblk.c
index 26ac145e..ed6e3e09 100644
--- a/ext2fs/getblk.c
+++ b/ext2fs/getblk.c
@@ -100,8 +100,9 @@ ext2_alloc_block (struct node *node, block_t goal, int zero)
     }
 
   /* Trap trying to allocate superblock, block group descriptor table, or beyond the end */
-  assert_backtrace (result >= group_desc_block_end
-		 && result < store->size >> log2_block_size);
+  assert_backtrace (result == 0 ||
+		    (result >= group_desc_block_end
+		     && result < store->size >> log2_block_size));
 #else
   result = ext2_new_block (goal, 0, 0);
 #endif
