Bug 673303

Summary: convert spits out rubbish to standard output
Product: [openSUSE] openSUSE 11.3 Reporter: Christopher Yeleighton <giecrilj>
Component: OtherAssignee: Petr Gajdos <pgajdos>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P3 - Medium CC: meissner
Version: Final   
Target Milestone: ---   
Hardware: x86-64   
OS: openSUSE 11.3   
URL: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=18037&p=68978#p68978
Whiteboard: .
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Deadline: 2011-10-06   

Description Christopher Yeleighton 2011-02-18 10:39:52 UTC
User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; pl-PL; rv:1.9.2.13) Gecko/20101203 SUSE/3.6.13-0.2.1 Firefox/3.6.13

convert, part of ImageMagick, emits error messages to standard output.  These error messages are probably supposed to contain library and source file references; they contain God knows what instead.

The problem goes away with ImageMagick 6.6.5 compiled against libtool 2.4 (which I cannot provide the package on OBS because of Bug 671303.

Reproducible: Always

Steps to Reproduce:
1. { convert logo: -annotate 0 +710 +1570 SAD null: |& iconv; }
2.
3.
Actual Results:  
  1. 
convert: unable to open image `+1570': 
`iconv: illegal input sequence at position 40

Expected Results:  
  1. Full error message from convert
Comment 1 Christopher Yeleighton 2011-02-21 16:51:16 UTC
Oops, my bad: malformed text gets printed to standard error.
Comment 2 Wei Wang 2011-02-23 09:13:41 UTC
(In reply to comment #1)
> Oops, my bad: malformed text gets printed to standard error.
So ,it is not a bug ? I close it ,please reopen it if I am wrong .
Comment 3 Christopher Yeleighton 2011-02-24 11:05:43 UTC
It is just like in the old April Fools‘ joke:

— Mom, Mom, come quick!  Dad has hanged himself in the attic!
— But there is nobody here!
— Mom, it is April Fools’!  Dad has hanged himself in the basement!

Reopening.
Comment 4 Christopher Yeleighton 2011-03-03 15:17:19 UTC
This is resolved upstream and available in Graphics, so switching to the Graphics repository will fix the bug.  However, this bug must remain open until an update is pushed to Updates (IMHO).
Comment 5 Petr Gajdos 2011-08-16 08:40:54 UTC
(In reply to comment #4)
> This is resolved upstream and available in Graphics, so switching to the
> Graphics repository will fix the bug.  However, this bug must remain open until
> an update is pushed to Updates (IMHO).

Not sure if wrong error message is important enough to do an update. Mr. Maintenance, what's your opinion?
Comment 6 Christopher Yeleighton 2011-08-16 10:13:45 UTC
The reason of this distortion seems to be a stack corruption in the x64 world.

* <URL: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=18662 >

Not nice.  However, if you feel like letting it go because printf is not a good attack vector, how about fixing that one?

* <URL: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=18282&p=70505&hilit=TIFF#p70505 >
Comment 7 Petr Gajdos 2011-08-16 10:54:49 UTC
(In reply to comment #6)
> The reason of this distortion seems to be a stack corruption in the x64 world.
> 
> * <URL: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=18662 >
> 
> Not nice.  However, if you feel like letting it go because printf is not a good

That's to be decided by openSUSE maintenance team. Nevertheless thanks for information, good to know.

> attack vector, how about fixing that one?
> * <URL:
> http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=18282&p=70505&hilit=TIFF#p70505
> >

The same as above. That's bug 682238, you can reopen it and ask maintenance team for an update as I did for this bug.

Thanks
Comment 8 Marcus Meissner 2011-08-16 12:15:40 UTC
I doubt ThrowWandException is the cause of this, as the error above is a file open error. I suspect another error position.

The ThrowWandException macro is of course also buggy, as it seems it calls fprintf(stderr,"%s %s %lu %s",2 arguments) is called instead with 4 arguments in nearly all occurences of
#define ThrowWandException(wand) \

This will also result in garbage being printed 


The bad color conversion is yet another bug, as Petr wrote, do not mix it into this one.



Not sure if we want a version update of ImageMagick to fix this, only if you consider it sensible, Petr.
Comment 9 Christian Dengler 2011-08-16 12:50:39 UTC
+1 if we get an OK from Petr.
Comment 10 Petr Gajdos 2011-08-16 13:39:36 UTC
I am not sure if version update of ImageMagick wouldn't be problematic
http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=12841
Comment 11 Christian Dengler 2011-08-19 12:45:29 UTC
Petr,

backport possible?
Comment 12 Petr Gajdos 2011-08-22 07:44:19 UTC
(In reply to comment #11)
> Petr,
> 
> backport possible?

I will look into it later.
Comment 13 Petr Gajdos 2011-09-06 14:26:01 UTC
Hmm,

strerror in GetExceptionMessage returns invalid pointer, no idea why so far. There should be "No such file or directory" after "`+1570': ".




MagickExport char *GetExceptionMessage(const int error)
{
  char
    exception[MaxTextExtent];

#if defined(MAGICKCORE_HAVE_STRERROR_R)
  (void) strerror_r(error,exception,sizeof(exception));
#else
  (void) CopyMagickString(exception,strerror(error),sizeof(exception));
#endif
  return(ConstantString(exception));
}
Comment 14 Marcus Meissner 2011-09-06 14:54:25 UTC
sterror_r has funny semantics.

man 3 sterror_r

       The GNU-specific strerror_r() returns a pointer to a string containing the error message.  This may  be  either  a
       pointer to a string that the function stores in buf, or a pointer to some (immutable) static string (in which case
       buf is unused).  If the function stores a string in buf, then at most buflen bytes are stored (the string  may  be
       truncated if buflen is too small) and the string always includes a terminating null byte.


it seems we use thje _GNU_SOURCE version, where the passed in buffer might
be unused.

so it should use the return value of strerror_r() here.
Comment 15 Petr Gajdos 2011-09-06 15:26:01 UTC
Yep,

use of strerror_r, no use of strerror is culprit here. I could read man-pages more carefully :-). Thanks Marcus!

So following could be upstreamable? As far as I can see this is issue in trunk too (even if they added *exception = '\0' before strerror_r call, so garbage vanished from the error message).

--- magick/exception.c  2011-09-06 15:31:15.000000000 +0200
+++ magick/exception.c  2011-09-06 17:11:20.000000000 +0200
@@ -458,7 +458,11 @@ MagickExport char *GetExceptionMessage(c
     exception[MaxTextExtent];

 #if defined(MAGICKCORE_HAVE_STRERROR_R)
-  (void) strerror_r(error,exception,sizeof(exception));
+  #if !defined(_GNU_SOURCE)
+    (void) strerror_r(error,exception,sizeof(exception));
+  #else
+    (void) CopyMagickString(exception,strerror_r(error, exception, sizeof(exception)),sizeof(exception));
+  #endif
 #else
   (void) CopyMagickString(exception,strerror(error),sizeof(exception));
 #endif
Comment 16 Petr Gajdos 2011-09-06 15:27:01 UTC
Affected: 11.3, 11.4 and Factory
Comment 17 Marcus Meissner 2011-09-06 16:02:43 UTC
perhaps to the return(ConstantString(....));
in all the ifs where possible.

not sure if this saves the CopyMagickString()

otherwise fine I think.
Comment 18 Petr Gajdos 2011-09-07 09:29:44 UTC
Filled upstream bug
http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=19436
Comment 19 Petr Gajdos 2011-09-07 09:34:01 UTC
Fixed for factory: sr#81191
Comment 20 Petr Gajdos 2011-09-07 09:35:33 UTC
Packages are prepared in home:pgajdos:branches:openSUSE:{11.3,11.4}:Update:Test. Should I submit them?
Comment 21 Marcus Meissner 2011-09-07 09:41:34 UTC
fine for me +1
Comment 22 Bernhard Wiedemann 2011-09-07 10:00:11 UTC
This is an autogenerated message for OBS integration:
This bug (673303) was mentioned in
https://build.opensuse.org/request/show/81191 Factory / ImageMagick
Comment 23 Petr Gajdos 2011-09-07 10:33:01 UTC
Done.
Comment 24 Bernhard Wiedemann 2011-09-07 11:00:10 UTC
This is an autogenerated message for OBS integration:
This bug (673303) was mentioned in
https://build.opensuse.org/request/show/81268 11.4 / ImageMagick
https://build.opensuse.org/request/show/81269 11.3 / ImageMagick
Comment 25 Swamp Workflow Management 2011-09-08 13:05:49 UTC
The SWAMPID for this issue is 43116.
This issue was rated as low.
Please submit fixed packages until 2011-10-06.
Also create a patchinfo file using this link:
https://swamp.suse.de/webswamp/wf/43116
Comment 26 Petr Gajdos 2011-09-08 13:58:06 UTC
Patchinfo created.
Comment 27 Petr Gajdos 2011-09-08 15:01:02 UTC
Christopher, thanks for reporting.
Closing as fixed.
Comment 28 Bernhard Wiedemann 2011-09-16 12:00:18 UTC
This is an autogenerated message for OBS integration:
This bug (673303) was mentioned in
https://build.opensuse.org/request/show/82369 Factory / ImageMagick
Comment 29 Swamp Workflow Management 2011-09-20 11:26:20 UTC
Update released for: ImageMagick, ImageMagick-debuginfo, ImageMagick-debugsource, ImageMagick-devel, ImageMagick-doc, ImageMagick-extra, ImageMagick-extra-debuginfo, libMagick++-devel, libMagick++3, libMagick++3-debuginfo, libMagick++4, libMagick++4-debuginfo, libMagickCore3, libMagickCore3-debuginfo, libMagickCore4, libMagickCore4-debuginfo, libMagickWand3, libMagickWand3-debuginfo, libMagickWand4, libMagickWand4-debuginfo, perl-PerlMagick, perl-PerlMagick-debuginfo
Products:
openSUSE 11.3 (debug, i586, x86_64)
openSUSE 11.4 (debug, i586, x86_64)