normalize_audio: robust in-place replace (fix Windows file.rename) - #24
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 uncheckedfile.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).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):Version stays 0.2.0: this folds into the release, which hasn't been submitted yet.