From 55b6e07a0fe9c2e18778c233f254fd274b6c0bb8 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Mon, 7 Aug 2023 17:21:15 +0200 Subject: [PATCH] Userland: Open files for save in write-only mode WavWriter and the shot utility open files with this mode and never truncate the files, which might leave some contents of a previous file during overwriting. --- Userland/Libraries/LibAudio/WavWriter.cpp | 2 +- Userland/Utilities/shot.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibAudio/WavWriter.cpp b/Userland/Libraries/LibAudio/WavWriter.cpp index a771d89b6e..466928a228 100644 --- a/Userland/Libraries/LibAudio/WavWriter.cpp +++ b/Userland/Libraries/LibAudio/WavWriter.cpp @@ -33,7 +33,7 @@ WavWriter::~WavWriter() ErrorOr WavWriter::set_file(StringView path) { - m_file = TRY(Core::File::open(path, Core::File::OpenMode::ReadWrite)); + m_file = TRY(Core::File::open(path, Core::File::OpenMode::Write)); TRY(m_file->seek(44, SeekMode::SetPosition)); m_finalized = false; return {}; diff --git a/Userland/Utilities/shot.cpp b/Userland/Utilities/shot.cpp index e3c0a1cd6e..854a4d6222 100644 --- a/Userland/Utilities/shot.cpp +++ b/Userland/Utilities/shot.cpp @@ -160,7 +160,7 @@ ErrorOr serenity_main(Main::Arguments arguments) if (edit_image) output_path = Core::DateTime::now().to_deprecated_string("/tmp/screenshot-%Y-%m-%d-%H-%M-%S.png"sv); - auto file_or_error = Core::File::open(output_path, Core::File::OpenMode::ReadWrite); + auto file_or_error = Core::File::open(output_path, Core::File::OpenMode::Write); if (file_or_error.is_error()) { warnln("Could not open '{}' for writing: {}", output_path, file_or_error.error()); return 1;