Skip to content

normalize_audio: robust in-place replace (fix Windows file.rename) - #24

Merged
TroyHernandez merged 1 commit into
mainfrom
fix/normalize-audio-inplace
Jul 24, 2026
Merged

normalize_audio: robust in-place replace (fix Windows file.rename)#24
TroyHernandez merged 1 commit into
mainfrom
fix/normalize-audio-inplace

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

Pre-submission fix from a review pass.

The bug

In-place normalize_audio() writes to a tempfile in the session tempdir, then moved it over the original with an unchecked file.rename() (R/audio.R:98). Two failure modes, both Windows-relevant:

  • file.rename() fails across filesystems, and the session tempdir is routinely on a different volume than the user's file (especially on Windows).
  • On Windows, file.rename() fails outright when the destination already exists, which in-place it always does.

Either way the rename returned FALSE, the move was skipped, and the function still returned the path as success: the normalized audio was silently dropped and the original left untouched.

Fix

file.copy(out_path, output, overwrite = TRUE) + unlink(), which works across volumes and overwrites on every platform, with the result checked (errors instead of silently succeeding).

Test

The old at_home test checked only existence + duration, which both still pass when the move silently fails (the untouched original has the same duration), so it could never have caught this. Strengthened it to compare the file's bytes before/after the in-place pass.

Verification (all at 0.2.0)

Real-ffmpeg at_home suite: 245/245 on Linux and Windows (was 244; +1 byte-diff check). R CMD check --as-cran, all 1 NOTE (New submission):

Env Result
Ubuntu 24.04, R 4.6.0 0E / 0W / 1N
Windows 10, R 4.6.0 0E / 0W / 1N
Windows 10, R-devel 0E / 0W / 1N

Version stays 0.2.0: this folds into the release, which hasn't been submitted yet.

In-place normalization writes to a tempfile in the session tempdir, then
moved it over the original with an unchecked file.rename(). Two ways that
breaks, both Windows-relevant and both missed by the at_home-gated test:

- file.rename() fails across filesystems, and the session tempdir is
  routinely on a different volume than the user's file (esp. Windows).
- On Windows, file.rename() fails outright when the destination exists,
  which in-place it always does.

Either way the rename returned FALSE, the move was skipped, and the
function still returned the path as if it had succeeded: the normalized
audio was silently dropped and the original left untouched.

Replace with file.copy(out_path, output, overwrite = TRUE) + unlink,
which works across volumes and overwrites on every platform, and check
the result, erroring instead of silently succeeding.

Strengthen the at_home test to compare the file's bytes before and after:
existence + duration alone pass even when the move silently fails (the
untouched original still has the same duration), so the old test could
not have caught this.
@TroyHernandez
TroyHernandez merged commit 3fcf761 into main Jul 24, 2026
2 checks passed
@TroyHernandez
TroyHernandez deleted the fix/normalize-audio-inplace branch July 24, 2026 21:32
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.

1 participant