Bug 507174 - When overwriting an existing file, it is written into instead
Summary: When overwriting an existing file, it is written into instead
Status: RESOLVED FIXED
Alias: None
Product: Skanpage
Classification: Applications
Component: general (other bugs)
Version First Reported In: 25.04.3
Platform: Arch Linux Linux
: VHI normal
Target Milestone: ---
Assignee: Alexander Stippich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-17 22:57 UTC by Jeff Robertson
Modified: 2025-07-20 20:11 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Robertson 2025-07-17 22:57:41 UTC
SUMMARY
When using the "Save All" button, and selecting an existing file, the user is prompted whether they wish to overwrite that file. If they say yes, the existing file is not removed. Instead, new PDF data is written into the beginning of the existing file. If the existing file is larger than the new data being written, the file is not truncated.

This bug is similar to https://en.wikipedia.org/wiki/ACropalypse since if the resulting file is shared it may include any private data from the original "overwritten" file.

STEPS TO REPRODUCE
1. Get a big PDF. I chose the 27MB Lancer core rulebook from https://massif-press.itch.io/corebook-pdf-free
2. Run binwalk over the pdf and note the page start offsets

Example:
binwalk Lancer\ -\ Free\ Version.pdf
------------------------------------------------------------------------------------------------------------
DECIMAL                            HEXADECIMAL                        DESCRIPTION
------------------------------------------------------------------------------------------------------------
0                                  0x0                                PDF document, version 1.7
8903                               0x22C7                             JPEG image, total size: 497696 bytes
567138                             0x8A762                            JPEG image, total size: 687848 bytes
1256109                            0x132AAD                           JPEG image, total size: 261110 bytes
1518597                            0x172C05                           JPEG image, total size: 289003 bytes
1844873                            0x1C2689                           JPEG image, total size: 415403 bytes
etc.

3. Run skanpage, scan one page with the "Scan" button, and save using the "Save All" button. Choose the large pdf in the file picker and click Save, then click Overwrite in the resulting popup.
4. binwalk the pdf again and note that page 1 has been overwritten, but most other pages are still there at their original locations

Example:
binwalk Lancer\ -\ Free\ Version.pdf
------------------------------------------------------------------------------------------------------------
DECIMAL                            HEXADECIMAL                        DESCRIPTION
------------------------------------------------------------------------------------------------------------
0                                  0x0                                PDF document, version 1.4
2027                               0x7EB                              JPEG image, total size: 994611 bytes
1256109                            0x132AAD                           JPEG image, total size: 261110 bytes
1518597                            0x172C05                           JPEG image, total size: 289003 bytes
1844873                            0x1C2689                           JPEG image, total size: 415403 bytes

There is a new jpeg from skanpage at offset 2027. The remaining jpegs at offsets 1256109, 1518597, 1844873, etc. are all carried over from the original large file.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 6.4.3
KDE Frameworks Version: 6.16.0
Qt Version: 6.9.1
Comment 1 Jeff Robertson 2025-07-18 01:48:55 UTC
MR at https://invent.kde.org/utilities/skanpage/-/merge_requests/106
Comment 2 Jeff Robertson 2025-07-19 16:07:03 UTC
Git commit de3ad2941054a26920e022dc7c4a3dc16c065b5a by Jeff Robertson.
Committed on 19/07/2025 at 15:35.
Pushed by ngraham into branch 'master'.

Truncate existing files when overwriting

WriteOnly mode truncates existing files when overwriting,
but ReadWrite does not.

https://doc.qt.io/qt-6/qiodevicebase.html

M  +1    -1    src/DocumentSaver.cpp

https://invent.kde.org/utilities/skanpage/-/commit/de3ad2941054a26920e022dc7c4a3dc16c065b5a
Comment 3 Albert Astals Cid 2025-07-20 20:11:11 UTC
Git commit 19308900da27b46739f2360426b91479e7179a2f by Albert Astals Cid, on behalf of Jeff Robertson.
Committed on 20/07/2025 at 20:11.
Pushed by aacid into branch 'release/25.08'.

Truncate existing files when overwriting

WriteOnly mode truncates existing files when overwriting,
but ReadWrite does not.

https://doc.qt.io/qt-6/qiodevicebase.html
(cherry picked from commit de3ad2941054a26920e022dc7c4a3dc16c065b5a)

M  +1    -1    src/DocumentSaver.cpp

https://invent.kde.org/utilities/skanpage/-/commit/19308900da27b46739f2360426b91479e7179a2f