From d9d09ef7388e9582d3882d3b2fb4969700baf1a2 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 9 Sep 2021 16:53:33 +0200 Subject: [PATCH] Don't allow saving over read-only files BUGS: 440986 --- part/part.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/part/part.cpp b/part/part.cpp index 2c3f1deaa..3cb0b52dd 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -2545,6 +2545,15 @@ bool Part::saveAs(const QUrl &saveUrl, SaveAsFlags flags) // Figure out the real save url, for symlinks we don't want to copy over the symlink but over the target file const QUrl realSaveUrl = resolveSymlinksIfFileExists(saveUrl); + // Due to the way we write we can overwrite readonly files so check if it's one and just bail out early + if (realSaveUrl.isLocalFile()) { + const QFileInfo fi(realSaveUrl.toLocalFile()); + if (fi.exists() && !fi.isWritable()) { + KMessageBox::information(widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", realSaveUrl.toLocalFile())); + return false; + } + } + QScopedPointer tempFile; KIO::Job *copyJob = nullptr; // this will be filled with the job that writes to saveUrl