bugGNU Octave - Bugs: bug #40267, imread ('default.img') causes...


bug #40267: imread ('default.img') causes segfault

Submitter:  Rik <rik5>
Submitted:  Mon 14 Oct 2013 06:20:59 PM UTC
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Fixed Assigned to:  carandraug
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


Sat 23 Nov 2013 11:04:54 PM UTC, comment #5: 

By the way, I generated the PNG image with the following:

[old_img, old_map] = imread ("default.img");

new_map = zeros (numel (unique (old_img(:))), 3);
new_img = zeros (size (old_img), "uint8");

n = 0;
for row = 1:rows(old_map)
  mask = old_img == row;
  if (any (mask(:)))
    new_img(mask) = n++;
    new_map(n,:)  = old_map(row, :);
imwrite (new_img, new_map, "new-default.img")

This code also converts the indexed image to uint8 (there's only 56 entries) and removes unnecessary entries from the colormap. After, I ran pngcrush which further reduced the size of the png file.

Carnë Draug <carandraug>
Project Member
Sat 23 Nov 2013 07:22:03 PM UTC, comment #4: 

I have converted the image file to PNG. The thing is that there's a few places in the source that use default.img. Should I:

  • still name the file "default.png" since GraphicsMagick is able to identify as PNG independently of the extension, just in case there's anyone out there also calling the function;
  • remove default.img and add a default.png
  • keep both, making one of them a symlink to the other (I don't know how mercurial handles symlinks though)
Carnë Draug <carandraug>
Project Member
Sun 20 Oct 2013 07:03:05 PM UTC, comment #3: 

Alright, I'm closing the bug report since the try/catch block now prevents the segfault.  Last remaining issue is the need to convert 'default.img' to 'default.png'.

Rik <rik5>
Project Administrator
Sun 20 Oct 2013 05:10:08 PM UTC, comment #2: 

1) yes.

2) fixed with cset 292319fb7fcc. Took me a while to get the cause of it because the reading was already in a try/catch block and I couldn't understand why it was not being caught. the exception was being thrown from the call to ping().

3) Because GM can do it. Try the following:

echo "hello world" > img.txt
gm identify img.txt
gm display img.txt

If you take a closer look to that "all white image", you'll notice that it also has the words "hello world" in black somewhere. I can see them with imshow().

We are relying on GM to decide what it can read and not. We could blacklist some of the coders though. By the way, GM should be able to read matlab files as well. See http://www.graphicsmagick.org/formats.html

Carnë Draug <carandraug>
Project Member
Sat 19 Oct 2013 02:49:34 PM UTC, comment #1: 


Three questions:

1) Can we go ahead and recode default.img to default.png?  Octave doesn't need this legacy format.

2) Can we use a try/catch block in C++ so that whatever routine in GM that fails doesn't cause Octave to abort?  Really, Octave should just know that the read failed and report that to the user with the error() function.

3) Why does reading a clearly incorrect file, return an image rather than an error?  I created a file called img.txt with the words "Hello World" in it.  This is clearly not an image file of any sort and yet I got back an all-white image with dimensions 792x612.

Rik <rik5>
Project Administrator
Mon 14 Oct 2013 06:20:59 PM UTC, original submission:  

On the development branch with a recent tip (17652:57750dc54ab6), the following comand produces a segfault.

imread ('default.img')
warning: your version of GraphicsMagick limits images to 8 bits per pixel
terminate called after throwing an instance of 'Magick::ErrorMissingDelegate'
  what():  Magick: No decode delegate for this image format (/home/rik/wip/Projects_Mine/octave-dbg/scripts/image/default.img) reported by magick/constitute.c:8285 (ReadImage)
panic: Aborted -- stopping myself...

Rik <rik5>
Project Administrator


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.





    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-10-20 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
    2013-10-17 rik5 Assigned toNone carandraug

    Back to the top

    Powered by Savane 3.9