Bug 502500

Summary: Icons corrupted in generated project
Product: [Developer tools] kapptemplate Reporter: argonel <argonel>
Component: generalAssignee: argonel <argonel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: 0.1.250390   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description argonel 2025-04-06 22:21:02 UTC
SUMMARY
Any binary files in templates can be corrupted when the project is generated.


STEPS TO REPRODUCE
1. Run KAppTemplate
2. Generate a "C++ KDE Frameworks" project
3. Open the icons folder in the generated project
4. Open one of the icons or the svg

OBSERVED RESULT
An error "Loading ‘16-apps-corrupt.png’ failed. Loading meta information failed." was displayed in Gwenview instead of the expected image. Upon inspection of the file, it was found to be corrupted with many replacement chars (U+FFFD):

$ cd /tmp/corrupt/icons
$ xxd 16-apps-corrupt.png  | head -n1
00000000: efbf bd50 4e47 0d0a 1a0a 0000 000d 4948  ...PNG........IH

The installed file sizes are clearly larger:
$ du -b *
1093    16-apps-corrupt.png
1488    22-apps-corrupt.png
2225    32-apps-corrupt.png
3378    48-apps-corrupt.png
202     CMakeLists.txt
3278    sc-apps-corrupt.svgz


EXPECTED RESULT
The first 16 bytes of the file should be:

$ cd sdk/kapptemplate/src/templates/C++/kde-frameworks6/icons
$ xxd 16-apps-%\{APPNAMELC\}.png | head -1
00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452  .PNG........IHDR

$ du -b *
625     16-apps-%{APPNAMELC}.png
802     22-apps-%{APPNAMELC}.png
1231    32-apps-%{APPNAMELC}.png
1862    48-apps-%{APPNAMELC}.png
258     CMakeLists.txt
1780    sc-apps-%{APPNAMELC}.svgz


SOFTWARE/OS VERSIONS
Linux/KDE Plasma:
KDE Plasma Version: 6.3.0
KDE Frameworks Version: 6.11.0
Qt Version: 6.8.2

ADDITIONAL INFORMATION
The installed archives found under /usr/share/kdevappwizard/templates are not corrupted, so this is not a packaging problem:

$ cd sdk/kapptemplate/src/templates/C++/kde-frameworks6/icons
$ cmp -l <(tar -jf /usr/share/kdevappwizard/templates/kde-frameworks6.tar.bz2 -x './icons/16-apps-%{APPNAMELC}.png' -O) 16-apps-%{APPNAMELC}.png && echo Same!
Same!
$
Comment 1 Bug Janitor Service 2025-04-07 06:13:15 UTC
A possibly relevant merge request was started @ https://invent.kde.org/sdk/kapptemplate/-/merge_requests/16
Comment 2 argonel 2025-11-19 06:24:37 UTC
Git commit de5cd429631810c9a7dbaa24e27ec03fb2517d01 by Eli MacKenzie.
Committed on 19/11/2025 at 06:10.
Pushed by argonel into branch 'master'.

Only replace keywords in text files

Non-text files such as PNG and compressed SVG were being read in for
keyword substitution and then written back out as text, even if no
substitions were made. As a result they were corrupt in the generated
project.

If the mimetype of a file does not descend from text/plain, the file
will no longer be considered for keyword substitution.

Addtionally, only changed files are written.

M  +20   -9    src/application/generator.cpp

https://invent.kde.org/sdk/kapptemplate/-/commit/de5cd429631810c9a7dbaa24e27ec03fb2517d01
Comment 3 argonel 2025-11-27 03:23:31 UTC
Git commit 84b24ce69de030068e215d103f576b83fea53be4 by Eli MacKenzie.
Committed on 27/11/2025 at 03:23.
Pushed by argonel into branch 'release/25.12'.

Only replace keywords in text files

Non-text files such as PNG and compressed SVG were being read in for
keyword substitution and then written back out as text, even if no
substitions were made. As a result they were corrupt in the generated
project.

If the mimetype of a file does not descend from text/plain, the file
will no longer be considered for keyword substitution.

Addtionally, only changed files are written.


(cherry picked from commit de5cd429631810c9a7dbaa24e27ec03fb2517d01)

Co-authored-by: Eli MacKenzie <argonel@gmail.com>

M  +20   -9    src/application/generator.cpp

https://invent.kde.org/sdk/kapptemplate/-/commit/84b24ce69de030068e215d103f576b83fea53be4