Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 466798 - kde-base/libkdcraw-4.10.3 includes invalid icc profiles, can't be written by libpng-1.6
Summary: kde-base/libkdcraw-4.10.3 includes invalid icc profiles, can't be written by ...
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo KDE team
Whiteboard: fixed in 4.10.5, was: media-libs/lib...
Depends on:
Blocks: libpng16
  Show dependency tree
Reported: 2013-04-22 12:40 UTC by Francesco Riosa
Modified: 2013-07-21 20:10 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---

debug area 50003 digikam-50003.log (digikam-50003.log,11.92 KB, text/plain)
2013-04-22 12:40 UTC, Francesco Riosa

Note You need to log in before you can comment on or make changes to this bug.
Description Francesco Riosa 2013-04-22 12:40:11 UTC
Created attachment 346282 [details]
debug area 50003 digikam-50003.log

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

>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

emerge --info

Portage 2.2.0_alpha173 (default/linux/amd64/13.0, gcc-4.8.0, glibc-2.15-r3, 3.9.0-rc7-monfi x86_64)
System uname: Linux-3.9.0-rc7-monfi-x86_64-Intel-R-_Core-TM-_i7-3770K_CPU_@_3.50GHz-with-gentoo-2.2
KiB Mem:    11985064 total,   4400232 free
KiB Swap:   16777208 total,  16777208 free
Timestamp of tree: Mon, 22 Apr 2013 08:30:01 +0000
ld ld di GNU (GNU Binutils) 2.23.1
distcc 3.1 x86_64-pc-linux-gnu [enabled]
ccache version 3.1.9 [disabled]
app-shells/bash:          4.2_p45
dev-java/java-config:     2.2.0
dev-lang/python:          2.7.3-r3, 3.3.0-r1
dev-util/ccache:          3.1.9
dev-util/cmake:           2.8.11_rc2-r1::kde
dev-util/pkgconfig:       0.28
sys-apps/baselayout:      2.2
sys-apps/openrc:          0.11.8
sys-apps/sandbox:         2.6-r1
sys-devel/autoconf:       2.13, 2.69
sys-devel/automake:       1.10.3, 1.11.6, 1.13.1
sys-devel/binutils:       2.23.1
sys-devel/gcc:            4.8.0
sys-devel/gcc-config:     1.8
sys-devel/libtool:        2.4.2
sys-devel/make:           3.82-r4
sys-kernel/linux-headers: 3.8 (virtual/os-headers)
sys-libs/glibc:           2.15-r3
Repositories: gentoo sabayon sabayon-distro qt x11 kde mysql vivovl digikam systemd-love
ACCEPT_KEYWORDS="amd64 ~amd64"
CFLAGS="-O2 -march=corei7-avx -pipe -frecord-gcc-switches  -mno-bmi2 -mno-avx2 -mno-lzcnt -mrdrnd --param=l1-cache-size=32"
CONFIG_PROTECT="/etc /etc/conf.d /etc/init.d /usr/share/config /usr/share/config/kdm /usr/share/gnupg/qualified.txt /usr/share/polkit-1/actions /usr/share/themes/oxygen-gtk/gtk-2.0 /usr/share/themes/oxygen-gtk/gtk-3.0 /var/lib/hsqldb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.5/ext-active/ /etc/php/cgi-php5.5/ext-active/ /etc/php/cli-php5.5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/skel /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -march=corei7-avx -pipe -frecord-gcc-switches  -mno-bmi2 -mno-avx2 -mno-lzcnt -mrdrnd --param=l1-cache-size=32 -fvisibility-inlines-hidden -fabi-version=6 -ffor-scope -fstrict-enums -fuse-cxa-atexit"
EMERGE_DEFAULT_OPTS="--ask-enter-invalid --quiet-build=y --buildpkg-exclude=x11-drivers/nvidia-drivers --buildpkg-exclude=sys-power/bbswitch --buildpkg-exclude=app-emulation/virtualbox-modules --buildpkg-exclude=sys-fs/aufs3"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs clean-logs compress-build-logs compressdebug config-protect-if-modified distcc distlocks ebuild-locks fail-clean fixlafiles installsources merge-sync news noinfo notitles parallel-fetch parallel-install sandbox sfperms skiprocheck splitdebug strict test-fail-continue unknown-features-warn unmerge-logs unmerge-orphans xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS=" rsync:// rsync://"
INSTALL_MASK=" /usr/lib64/elektra/*.la /usr/lib64/libelektra*.la /usr/lib64/libo{{,sp}grove,style}.la /lib/udev/rules.d/45-Argyll.rules /usr/lib64/terminfo/[0-9] /usr/src/debug /usr/lib64/debug/ "
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--build-id"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTDIR_OVERLAY="/g/ovl/for-gentoo /g/ovl/sabayon /g/ovl/qt /g/ovl/x11 /g/ovl/kde /g/ovl/mysql /g/ovl/tmp /g/ovl/digikam /g/ovl/systemd-love"
USE="X a52 aac accessibility acl acpi aiglx aim alsa amd64 artswrappersuid audiofile avahi bash-completion berkdb bidi bluetooth bzip2 cairo cdda cddb cdr cjk cli cpudetection cracklib crypt cups cxx dbus dga dri dts dv dvb dvd dvdr dvdread dvi efi egl fame fat ffmpeg firefox flac foomatic-db fortran freetype gcj gdbm gif gimpprint gles2 gmp gnutls gphoto2 gpm gsm gtk hfs iconv icq ieee1394 imap inotify ipod ipv6 irc irda jabber jack jfs joystick kdeenablefinal kdehiddenvisibility kerberos lame lcd libnotify live lm_sensors lzo mail matroska mjpeg mmx modules mozdevelop mp3 mp3rtp msn mudflap multilib musepack musicbrainz ncurses network nls nptl nsplugin ntfs ogg openal openexr opengl openmp pam pcmcia pcre pda perl png policykit ppds pulseaudio python qt3support qt4 rar rdesktop readline reiserfs rss scanner sdl session slp smpeg speex sse sse2 ssl startup-notification stream svg sysfs systemd tcpd theora tiff udev unicode usb v4l v4l2 visualization wifi wmf x264 xattr xcb xfs xine xinerama xpm xprint xulrunner xvid xvmc yahoo zeroconf zlib" ABI_X86="64" ALSA_CARDS="emu10k1x darla20 darla24 emu10k1 gina20 gina24 hdsp hdspm ice1712 indigo indigoio layla20 layla24 mia mixart mona pcxhr rme32 rme96 sb16 sbawe sscape usbusx2y vx222 usb-usx2y" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" APACHE2_MPMS="prefork" CALLIGRA_FEATURES="krita braindump flow stage words sheets" CAMERAS="agfa_cl20 casio_qv dimagev dimera3500 kodak_dc120 kodak_dc210 kodak_dc240 kodak_dc3200 kodak_ez200 konica_qm150 panasonic_coolshot panasonic_dc1000 panasonic_dc1580 panasonic_l859 polaroid_pdc320 polaroid_pdc640 polaroid_pdc700 ricoh_g3 sipix_blink sipix_blink2 sipix_web2 sony_dscf1 sony_dscf55 toshiba_pdrm11 adc65 aox barbie canon clicksmart310 digigr8 digita directory enigma13 fuji gsmart300 hp215 iclick jamcam jd11 konica largan lg_gsm mars mustek pccam300 pccam600 ptp2 ricoh samsung sierra smal sonix soundvision spca50x sq905 stv0674 stv0680 sx330z template" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" DRACUT_MODULES="caps cifs dmsquash-live livenet mdraid nfs ssh-client syslog systemd" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="evdev void" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer nlpsolver pdfimport scripting-beanshell scripting-javascript wiki-publisher" LINGUAS="it en en_US" LIRC_DEVICES="audio audio_alsa serial pctv" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-4" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7" QEMU_SOFTMMU_TARGETS="arm cris m68k microblaze mips mips64 mips64el mipsel ppc ppc64 ppcemb sh4 sh4eb sparc sparc64" QEMU_USER_TARGETS="arm x86_64" RUBY_TARGETS="ruby18 ruby19" USERLAND="GNU" VIDEO_CARDS="fbdev vesa radeonhd r300 r600 intel modesetting radeon" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Comment 1 Andreas K. Hüttel archtester gentoo-dev 2013-04-30 17:17:30 UTC
We cannot do much about this... Please file a bug on and link to it here for tracking.
Comment 2 Andreas K. Hüttel archtester gentoo-dev 2013-05-03 10:43:36 UTC
Which digikam version is this?
Comment 3 Francesco Riosa 2013-05-03 10:58:57 UTC
oops, this is from git, forgot to mention it before.
BTW the problem is still present with libpng-1.6.2, will look soon at it and try a patch
Comment 4 Francesco Riosa 2013-05-05 13:57:48 UTC
temporary workarond rename 
the program will complain but save the png
Comment 5 Francesco Riosa 2013-05-05 15:04:11 UTC

Both files are from kde-base/libkdcraw-4.10.2

the size seem to be correctly reported (3rd and 4th byte in file)
0x1B0A == 6922
-rw-r--r-- 1 root root 6922  1 mar 08.01 /usr/share/apps/libkdcraw/profiles/srgb-d65.icm

iccexamin (and opening the files with an hex editor) seem to confirm both profiles are ok, so not a bug for libkdcraw.

the bug seem to be in libpng being overzealous, see the following function from png.c

png_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,
   png_const_charp name, png_uint_32 profile_length)
   if (profile_length < 132)
      return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
         "too short");

   if (profile_length & 3)
      return png_icc_profile_error(png_ptr, colorspace, name, profile_length,
         "invalid length");

   return 1;

I don't know where the test (profile_length & 3) come from but it's failing, the function is undocumented and the git repository of libpng seem to be a dump for tarballs so my debugging stop here waiting for instructions
Comment 6 Andreas K. Hüttel archtester gentoo-dev 2013-05-05 16:17:00 UTC
Opened libpng bug with information from here
Comment 7 Francesco Riosa 2013-05-05 16:30:04 UTC
    for completeness:
    Table 17 — Profile header fields of section 7.2 in
    describes the first 128 bytes of an icc file
Comment 8 John Bowler 2013-05-05 19:12:08 UTC
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 9 Andreas K. Hüttel archtester gentoo-dev 2013-05-05 20:15:38 UTC
Back to team then... :]
Comment 10 Francesco Riosa 2013-05-06 09:06:22 UTC
profiles not aligned to 4 byte (~2100 pkg installed, not complete):

154323 app-office/calligra (/usr/share/color/icc/krita/lcmsxyzi.icm)
   827 app-office/calligra (/usr/share/color/icc/krita/scRGB.icm)
154326 app-office/calligra (/usr/share/color/icc/krita/lcmslabi.icm)
 28202 media-libs/lcms     (/usr/share/lcms/profiles/sRGBSpac.icm)
  6922 kde-base/libkdcraw  (/usr/share/apps/libkdcraw/profiles/srgb-d65.icm)
Comment 11 Francesco Riosa 2013-05-06 09:19:51 UTC
another note all these profiles have been created by lcms 2.1.0 and 2.3.0 under some microsoft platform.

lcms 2.4.0 is released and it would interesting to see if it also generate (or translate) profiles which are not aligned.

Marti M. hope you can see this
Comment 12 Marti Maria 2013-05-07 15:16:46 UTC
Hi, that's Marti, the author of lcms. 

I've taken a look on that and those bogus profiles comes from diverse origins. The "2.1" and "2.3" version stamp you see in the profile does *not* refer to littlecms library, but to the ICC spec they are supposed to follow. Current ICC spec is 4.3, so go figure how old those profiles are. I can identify lcmslab and lcmsxyz as being prototypes created by myself about 15 years ago, in the old days of lcms 1.1 I would just discard those profiles as they are actually useless. 
For the remaining ones, I searching in my profile collection I can find same file names but with size multiple of 4. I wonder if any spare bytes have been added by I don't know which magic process. Otherwise, the check is fine but probably too restrictive for untrusted environments and too permissive if you want to take security into account. The profile header contains the expected length, I would check that field and probably the MD5 id if you want to make sure the profile have not been stamped.
Comment 13 Francesco Riosa 2013-05-07 18:12:02 UTC
Gentooers what about the following plan?

1) fix profiles from lcms:0, put them in $FILESDIR, or even better remove them at all at install phase. Most (but far from all) application use lcms:2 nowadays
it should be lcms-1.19-r1 (current and stable is 1.19-r0)

2) app-office/calligra should be fixed upstream by next release but media-libs/libpng-1.6* could become stable before them.
Profiles should be fixed right now, without waiting for upstream with a temporary solution.
Sadly some profiles are big and don't fit well^W at all in $FILESDIR. This leaves us two option, first is to provide an additional package, second is to fix them on the fly:

in case you decide to fix on the fly at install phase here there is a short snipper of bash code that can help:

# pad an icc profile to 4bytes


oldsize=$(stat --printf='%s' "${PROFILENAME}")
newsize=$(( (oldsize +3 ) / 4 * 4 ))
if [[ $oldsize != $newsize ]] ; then
  # first pad the file
  for i in $(seq $(( newsize - oldsize)) ) ; do 
    echo -ne \\00 >> "${PROFILENAME}"
  # then replace the size in the header (the first 4 bytes)
  hexnewsize=$(printf '%08X\n' ${newsize})
  hexnewsize=$(echo ${hexnewsize}  | sed -e 's:..:\\x\0:g')
  sed -e '1s:^....:'${hexnewsize}':' -i "${PROFILENAME}"

be warned that sed MUST support the sintax 's/..../\x0D\x0A\x4D\x53\x48/' all gentoo provided should but please check

3) kde-base/libkdcraw same as calligra but without the size problem, the only profile affected is small
Comment 14 Francesco Riosa 2013-05-09 16:31:51 UTC
Safer version, use dd instead of sed and replace original file only after all operations are done, an even safer version would die() on errors

pad_icc() {
  local PROFILENAME="$1"
  local oldsize=$(stat --printf='%s' "${PROFILENAME}")
  local newsize=$(( (oldsize +3 ) / 4 * 4 ))
  local hexnewsize
  if [[ $oldsize != $newsize ]] ; then
    hexnewsize=$(printf '%08X\n' ${newsize})
    hexnewsize=$(echo ${hexnewsize}  | sed -e 's:..:\\x\0:g')
    # write the new size (4 byte file)
    echo -ne ${hexnewsize} > "${PROFILENAME}".new 
    # now append the original profile w/o the first 4 byte
    dd if="${PROFILENAME}" ibs=4 skip=1 >> "${PROFILENAME}".new
    # then pad to the wanted size
    for i in $(seq $(( newsize - oldsize)) ) ; do 
      echo -ne \\00 >> "${PROFILENAME}".new
    # finally move to the original
    mv "${PROFILENAME}".new  "${PROFILENAME}"

pad_icc profiles/srgb-d65.icm
Comment 15 Francesco Riosa 2013-05-09 17:22:59 UTC
libkdcraw should be fixed in next version, calligra/krita has a bug open@
Comment 16 Andreas K. Hüttel archtester gentoo-dev 2013-06-08 22:54:49 UTC
Francesco, how about you push your libkdcraw commit into KDE/4.10 branch too? Then it would be fixed in 4.10.5 ...
Comment 17 Francesco Riosa 2013-06-10 16:31:26 UTC
humm, no expert in backporting, but if the git cherry pick magic has been done right it would be commit  "92a57e163222ef9ee072964eb5cad92d9567a24d" in KDE/4.10
Comment 18 Samuli Suominen (RETIRED) gentoo-dev 2013-07-20 17:55:32 UTC
(In reply to Francesco Riosa from comment #17)
> humm, no expert in backporting, but if the git cherry pick magic has been
> done right it would be commit  "92a57e163222ef9ee072964eb5cad92d9567a24d" in
> KDE/4.10

this is fixed now? can we close the bug?

*libkdcraw-4.10.5 (02 Jul 2013)

  02 Jul 2013; Johannes Huber <> +libkdcraw-4.10.5.ebuild:
  Version bump KDE SC 4.10.5

libpng 1.6.3 going stable in 4 weeks
Comment 19 Michael Palimaka (kensington) gentoo-dev 2013-07-20 18:15:06 UTC
(In reply to Samuli Suominen from comment #18)
> (In reply to Francesco Riosa from comment #17)
> > humm, no expert in backporting, but if the git cherry pick magic has been
> > done right it would be commit  "92a57e163222ef9ee072964eb5cad92d9567a24d" in
> > KDE/4.10
> this is fixed now? can we close the bug?
> *libkdcraw-4.10.5 (02 Jul 2013)
>   02 Jul 2013; Johannes Huber <> +libkdcraw-4.10.5.ebuild:
>   Version bump KDE SC 4.10.5
It should be fixed, yes.

> libpng 1.6.3 going stable in 4 weeks
It is very likely that 4.10.5 will be stabilised before then so there shouldn't be any problems.
Comment 20 Francesco Riosa 2013-07-21 20:10:59 UTC