Bug 319267 - RawEngine contains invalid icc profiles, applications fail to save png file with libpng-1.6.x
Summary: RawEngine contains invalid icc profiles, applications fail to save png file w...
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Unclassified
Component: Plugin-DImg-RAW (show other bugs)
Version: 3.0.0
Platform: Other Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-03 10:47 UTC by Andreas K. Huettel
Modified: 2018-04-01 09:45 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 3.2.0


Attachments
srgb-d65.icm (6.76 KB, application/octet-stream)
2013-05-06 16:43 UTC, Francesco Riosa
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas K. Huettel 2013-05-03 10:47:08 UTC
This is a clone of https://bugs.gentoo.org/show_bug.cgi?id=466798

Saving a file into png format from `showfoto` (part of digikam) fails with error "libpng error: profile 'icc': 1B0Ah: invalid length"
It was working with libpng:1.5

From the debug log:
>usr>src$ showfoto
Fontconfig warning: "/etc/fonts/conf.d/50-user.conf", line 9: reading configurations from ~/.fonts.conf is deprecated.
"/org/freedesktop/UDisks2/drives/SAMSUNG_SSD_830_Series_S0XYNEAC664966" : property "Drive" does not exist
"/org/freedesktop/UDisks2/drives/WDC_WD1002FAEX_00Y9A0_WD_WCAW30075681" : property "Drive" does not exist
"/org/freedesktop/UDisks2/drives/WDC_WD1002FAEX_00Y9A0_WD_WCAW30058295" : property "Drive" does not exist
"/org/freedesktop/UDisks2/drives/Generic_Ultra_HS_SD_2fMMC_000000264001" : property "Drive" does not exist
"/org/freedesktop/UDisks2/drives/Kindle_Internal_Storage_B0241502243506JP" : property "Drive" does not exist
"/org/freedesktop/UDisks2/drives/ASUS____DRW_24B3LT_B4D0CL324524" : property "Drive" does not exist
"/org/freedesktop/UDisks2/drives/SAMSUNG_SSD_830_Series_S0XXNEAC626599" : property "Drive" does not exist
showfoto(25572)/digikam (core) Digikam::ThumbnailCreator::createThumbnail: Cannot create thumbnail for  "/home/vivo/docs/NIKON/2013/20130420-test/work/EditorWindow-k19287.digikamtempfile.png"
showfoto(25572)/digikam (core) Digikam::ThumbnailCreator::load: Thumbnail is null for  "/home/vivo/docs/NIKON/2013/20130420-test/work/EditorWindow-k19287.digikamtempfile.png"
showfoto(25572)/digikam (core) Digikam::ThumbnailCreator::createThumbnail: Cannot create thumbnail for  "/home/vivo/docs/NIKON/2013/20130420-test/work/EditorWindow-Ly7331.digikamtempfile.png"
showfoto(25572)/digikam (core) Digikam::ThumbnailCreator::load: Thumbnail is null for  "/home/vivo/docs/NIKON/2013/20130420-test/work/EditorWindow-Ly7331.digikamtempfile.png"
showfoto(25572)/digikam (core) Digikam::FileSaveOptionsBox::discoverFormat: Using fallback format  0
showfoto(25572)/digikam (core) Digikam::FileSaveOptionsBox::discoverFormat: Using fallback format  0
showfoto(25572)/digikam (core) Digikam::FileSaveOptionsBox::discoverFormat: Using fallback format  0
libpng error: profile 'icc': 1B0Ah: invalid length
showfoto(25572)/digikam (core) Digikam::EditorCore::slotImageSaved: error saving image ' /home/vivo/docs/NIKON/2013/20130420-test/work/EditorWindow-w25572.digikamtempfile.png

Note, things have been compiled with gcc-4.8.0 (!).
Comment 1 Francesco Riosa 2013-05-03 10:51:57 UTC
I plan to look at this next weekend 4/5-05/2013
Comment 2 Francesco Riosa 2013-05-05 15:43:02 UTC
after some research seem libpng cannot handle srgb-d65.icm from libkdcraw
Comment 3 Andreas K. Huettel 2013-05-05 20:25:23 UTC
From the Gentoo bug report:

--- Comment #8 from John Bowler <jbowler##acm.org> ---
ICC profiles are required to have a length which is a multiple of 4, so the
profile in question is broken.  (See 7.1.2(c) in the spec and "NOTE 1" that
follows it then read 7.2.2 - the length includes the pad bytes.)

I believe there was (and maybe is) an app that was writing text strings at the
end of the profile and, if the text string was not a multiple of 4 in length,
it would produce a bad profile.  Those profiles are easy to fix - just pad the
string with \0 - but other bugs where the profile length is calculated wrong
may result in serious errors.  (libpng does go on to validate the length, but
when the length is detectably broken at the start it simply rejects the
profile.)

This is a benign error on read and the profile will be ignored (along with any
other colorspace information in the PNG) but on write it gets converted into an
application error - we don't want to write PNGs with detectably broken
profiles, something else may crash!

The KDE upstream need to fix the profile, it should be easy.
Comment 4 Francesco Riosa 2013-05-06 10:04:22 UTC
krita in calligra also has some
Comment 5 Francesco Riosa 2013-05-06 16:43:05 UTC
Created attachment 79736 [details]
srgb-d65.icm

this profile has been padded with 0 to 6924 bytes (with okteta hex editor) and the header updated to the new size.
Comment 6 Francesco Riosa 2013-05-09 16:42:01 UTC
every upstream software (libpng and lcms) confirmed that icc profiles are padded to 4 byte and that the software involved is conformat since a looong time.

so it's ok to simply replace the original profile with a padded one.
Comment 7 Francesco Riosa 2013-05-09 16:46:07 UTC
Git commit ca2274e40d065e12123f6d32db3c6fe153e621a2 by Francesco Riosa.
Committed on 09/05/2013 at 18:41.
Pushed by riosa into branch 'master'.

ICC profiles should be padded to 4 bytes

In practice with libpng >= 1.6 the profile cannot be embedded if it has
the wrong size thus preventing digikam/showfoto to write png files at
all.

see also

M  +-    --    profiles/srgb-d65.icm

http://commits.kde.org/libkdcraw/ca2274e40d065e12123f6d32db3c6fe153e621a2
Comment 8 Francesco Riosa 2013-06-10 16:26:47 UTC
Git commit 92a57e163222ef9ee072964eb5cad92d9567a24d by Francesco Riosa.
Committed on 09/05/2013 at 18:41.
Pushed by riosa into branch 'KDE/4.10'.

ICC profiles should be padded to 4 bytes

In practice with libpng >= 1.6 the profile cannot be embedded if it has
the wrong size thus preventing digikam/showfoto to write png files at
all.

see also

M  +-    --    profiles/srgb-d65.icm

http://commits.kde.org/libkdcraw/92a57e163222ef9ee072964eb5cad92d9567a24d