test(gate): accept fact/other chunks — validate data chunk ends at EOF
sf.write() float32 WAVs carry a fact chunk; strict 44+data_size check was too narrow. Walk chunks instead; bridge header bug (half data_size) still caught because its data chunk must run to EOF.
This commit is contained in:
@@ -41,10 +41,19 @@ def harness_audit_null_test(original_path, rendered_path, threshold_db=THRESHOLD
|
||||
|
||||
def wav_format_info(path):
|
||||
with open(path, "rb") as f:
|
||||
b = f.read(44)
|
||||
b = f.read()
|
||||
assert b[:4] == b"RIFF" and b[8:12] == b"WAVE", "not RIFF/WAVE"
|
||||
data_size = struct.unpack_from("<I", b, 40)[0]
|
||||
assert os.path.getsize(path) == 44 + data_size, "data chunk size mismatch"
|
||||
# Walk chunks: "data" must run exactly to EOF (fact/other chunks allowed).
|
||||
pos = 12
|
||||
data_ok = False
|
||||
while pos + 8 <= len(b):
|
||||
cid = b[pos:pos + 4]
|
||||
size = struct.unpack_from("<I", b, pos + 4)[0]
|
||||
if cid == b"data":
|
||||
assert pos + 8 + size == len(b), "data chunk must end at EOF"
|
||||
data_ok = True
|
||||
pos += 8 + size + (size & 1) # chunks are word-aligned
|
||||
assert data_ok, "no data chunk"
|
||||
return {
|
||||
"fmt_tag": struct.unpack_from("<H", b, 20)[0],
|
||||
"channels": struct.unpack_from("<H", b, 22)[0],
|
||||
|
||||
Reference in New Issue
Block a user