Skip to content

Reject invalid audio dimensions before opening output files - #505

Open
BSAIPF wants to merge 1 commit into
bastibe:masterfrom
BSAIPF:contrib/fix-write-shape-before-open
Open

BSAIPF wants to merge 1 commit into
bastibe:masterfrom
BSAIPF:contrib/fix-write-shape-before-open

Conversation

@BSAIPF

@BSAIPF BSAIPF commented Oct 19, 2026

Copy link
Copy Markdown

sf.write(path, np.zeros((2, 2, 2)), 8000) opens and truncates the destination before rejecting the array dimensions. In a local reproduction, an existing three-frame WAV became an empty WAV even though the call raised ValueError.

Check for one or two dimensions immediately after np.asarray(), before opening SoundFile. Invalid dimensions now leave existing files and file-like objects untouched and do not create new files; scalar input raises ValueError instead of IndexError.

Validation:

  • All 9 regression cases fail before the fix and pass after it (scalar, 3-D and 4-D inputs; new paths, existing WAVs and BytesIO).
  • Full suite: 380 passed, with the same 16 callback warnings reproduced on the unchanged upstream source (371 passed).
  • Pyright: 0 errors, 0 warnings, before and after the change.

@bastibe

bastibe commented Oct 24, 2026

Copy link
Copy Markdown
Owner

How did you stumble upon this issue? Your account has activity only in the last month, so you're likely an AI.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants