Skip to content

Fix 64-bit superblock updates and add stress test#2

Open
JoneKone wants to merge 1 commit intomasterfrom
codex/reproduce-failure-and-audit-ext4-superblock-handling
Open

Fix 64-bit superblock updates and add stress test#2
JoneKone wants to merge 1 commit intomasterfrom
codex/reproduce-failure-and-audit-ext4-superblock-handling

Conversation

@JoneKone
Copy link
Owner

Summary

  • persist 64-bit block, reserved, and free counters in EXT2_VCB so the superblock high words are always restored before saving
  • teach the superblock save/update paths to use the 64-bit setter helpers and refresh the cached counters when the on-disk image is reloaded
  • add a Python stress test that demonstrates the corruption caused by truncating the counters and verifies the repaired superblock, with minimal Windows packing stubs so it can run on Unix

Testing

  • ./tests/64bit_superblock_stress.py

https://chatgpt.com/codex/tasks/task_e_68fcc3dd26608333972ecf9f81e02f82

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +15 to +37
def _build_crc32c_table() -> list[int]:
poly = 0x1EDC6F41
table = []
for i in range(256):
crc = i
for _ in range(8):
if crc & 1:
crc = (crc >> 1) ^ poly
else:
crc >>= 1
crc &= 0xFFFFFFFF
table.append(crc)
return table


CRC32C_TABLE = _build_crc32c_table()


def crc32c(data: bytes, crc: int = 0xFFFFFFFF) -> int:
"""Compute the CRC32C checksum using the kernel's convention."""
for b in data:
crc = CRC32C_TABLE[(crc ^ b) & 0xFF] ^ (crc >> 8)
crc &= 0xFFFFFFFF

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Generate CRC32C table with wrong polynomial orientation

The stress test builds its CRC table by shifting the CRC right and XORing with 0x1EDC6F41. That polynomial value is the non‑reflected CRC32C polynomial, so using it with a right‑shift algorithm produces an incorrect checksum. As written the script always writes an invalid superblock checksum even after repairing the block counters, causing e2fsck to continue failing. Use the reflected constant 0x82F63B78 (or a standard CRC32C implementation) when generating the table.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant