[solved] convert with comments crashes

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
lessertx
Posts: 4
Joined: 2016-05-30T15:51:25-07:00
Authentication code: 1151

[solved] convert with comments crashes

Post by lessertx »

Hi,
I apologize if this turns out to be a tcl problem but I found hints to the type of crash I see first in the ImageMagick mailing list.
I run from within a tcl script convert to add a comment to an image. The comment is scientific information that explains roughly how this image was produced. It worked well for a long time until an upgrade of either imagemagick or the operating system.

But first the problem:
*** glibc detected *** /usr/bin/convert: free(): invalid pointer: 0x0000000001e40251 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3d00475f3e]
/lib64/libc.so.6[0x3d00478d8d]
[rather long list of stuff excluded]
3d04825000-3d04a25000 ---p 00025000 fd:00 140096 /usr/lib64/libpng12.so.0.49.0child killed: SIGABRT
while executing
"exec $PGM_convert -comment "$com" tmp_plate.png crash_plate.png"
(file "./conv.tcl" line 15)

I isolated the problem to form this example (script)

Code: Select all

#! /usr/bin/tclsh
set PGM_convert    /usr/bin/convert;

set com "This is a comment that works\n"

exec $PGM_convert -comment "$com" tmp_plate.png com_plate.png

set com "\nThis is a comment that crashes\n"

exec $PGM_convert -comment "$com" tmp_plate.png crash_plate.png
# end of script
As you can see if the comment starts with a "\n" it crashes. And, any number of blanks in front of the \n still crash. If I use an undescore or so, it works. I do not see the crash when I use the command line in tcsh or sh interestingly enough.
convert --version
Version: ImageMagick 6.7.2-7 2016-05-09 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
uname -a
Linux name 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
CentOS 6.8

I suspect you can use any image (png) but if you need my image, I can provide it. Yes, I only tried png as file type.
But it used to work well. Unfortunately, I cannot tell anymore which version of IM worked or what else has changed exactly.
Thanks for any pointers.
Lothar
Last edited by lessertx on 2016-06-03T06:56:43-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert with comments crashes

Post by fmw42 »

IM 6.7.2.7 is very old (almost 200 versions old). Have you considered upgrading to the current IM 6.9.4.5. However, if it works under bash, then it would appear to be a Tcl issue. Sorry I do not use Tcl.
lessertx
Posts: 4
Joined: 2016-05-30T15:51:25-07:00
Authentication code: 1151

Re: convert with comments crashes

Post by lessertx »

Hi,
good advice but not quite perfect yet. I compiled ImageMagick 6.9.4-4 Q16 and it no longer crashes. In the past I only used yum update and I suspect the repo does not keep up.
However, it no longer honors any "\n" at the beginning incl. blanks. This does not seem like much but I definitely wanted as before:
identify -verbose plate.png
Properties:
comment:
Project 556
Condition: Salt
etc.
However I cannot get a newline right after comment anymore. It reads
Properties:
comment: Project 556
Condition: Salt.

I can probably insert some dummy stuff behind comment: but I think I should not have to if the behavior was as before. IM seems to delete \n and any blanks from the beginning of comments. Is this really necessary ?

Thanks. It is virtually solved but I am not totally happy yet.
Lothar
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert with comments crashes

Post by fmw42 »

It works fine for me on IM 6.9.4.5 Q16 Mac OSX Snow Leopard in a bash terminal window.

Code: Select all

convert -comment "\nline1\nline2" rose: rose2.png
convert rose2.png -format "%c\n" info:

line1
line2
Try -set comment after reading the image.

Code: Select all

convert rose: -set comment "\nline1\nline2".pnge 
convert rose.png -format "%c\n" info:

line1
line2
If neither work, is there an upgrade to Tcl to try?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert with comments crashes

Post by snibgo »

lessertx wrote:set com "\nThis is a comment that crashes\n"
I don't know TCL, but I query whether the two characters (backslash and lower-case 'n') are being passed to ImageMagick. You can test this by inserting "-debug all" into the convert command.
snibgo's IM pages: im.snibgo.com
lessertx
Posts: 4
Joined: 2016-05-30T15:51:25-07:00
Authentication code: 1151

Re: convert with comments crashes

Post by lessertx »

Hi fmw42,

although I can't get any of your other commands to work at all (convert tmp_plate: -set comment ...) but I did some more tests and it seems a tcl problem. I am using a fairly new tcl 8.5 version but it seems that the exec command strips the first /n and blanks from what it preceives an argument on a commandline. I used double quotes to protect spaces in the variable $com (for comments) as in "$com" - this we now know does not work. Better is '$com' but this produces extra single quotes in identify -verbose behind comment:' etc. I think I could live with that. So to save some time, we can consider this to be solved.
Thanks for your advice and patience.
Lothar

P.S. I did try convert debug -all but I was unable to find what I was looking for in the copious amount of output I do not understand :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert with comments crashes

Post by fmw42 »

(convert tmp_plate: -set comment ...)
Just to be clear, rose: (with the colon) is an internal Imagemagick image. Any real image with a suffix should not have a colon appended to it.

so try

Code: Select all

convert yourimage.suffix -set comment "your comment" resultimage.suffix
lessertx
Posts: 4
Joined: 2016-05-30T15:51:25-07:00
Authentication code: 1151

Re: [solved] convert with comments crashes

Post by lessertx »

Thanks I did not know that with rose:
I marked this as solved. It is still a bit puzzling to me what TCL did to make IM crash. Maybe the first character in the comment was NULL ? We may never know as this is probably going away.

Again, thanks to all.
Lothar
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: [solved] convert with comments crashes

Post by snibgo »

You want the two characters backslash and lower-case-n to be translated to Newline (0xa). This translation can be done either by TCL or IM.

The problem with doing it in TCL is that when you...

Code: Select all

exec $PGM_convert -comment "$com" tmp_plate.png crash_plate.png
... the $com will be expanded to include 0xa characters, which might do bad things to the exec. It would seem wiser to escape the backslash, so TCL won't translate \n into 0xa, but will pass two characters backslash and lower-case-n to IM.
snibgo's IM pages: im.snibgo.com
Post Reply