Bug 980672 - matio segfaults when opening invalid files
matio segfaults when opening invalid files
Product: Fedora
Classification: Fedora
Component: matio (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Clément DAVID
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2013-07-02 22:15 EDT by W. Michael Petullo
Modified: 2015-02-17 10:47 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2015-02-17 10:47:42 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description W. Michael Petullo 2013-07-02 22:15:19 EDT
Description of problem:
I maintain an application (dmapd) that makes use of VIPS. I am having
trouble with the application. The symptom is a segfault when processing
certain image files.

Version-Release number of selected component (if applicable):

How reproducible:
Every time

Steps to Reproduce:
I wrote a simple program that causes the crash when opening a particular JPEG file:

#include <vips/vips.h>

int main (int argc, char *argv[])
    VipsImage *im = vips_image_new_mode ("cam_hat.jpg", "rd");

Actual results:
(gdb) run
Starting program: /tmp/Cameron/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
__mempcpy_sse2 () at ../sysdeps/x86_64/memcpy.S:167
167             movb    %al, (%rdi)
(gdb) ba
#0  __mempcpy_sse2 () at ../sysdeps/x86_64/memcpy.S:167
#1  0x00007ffff202b1fe in __GI__IO_file_xsgetn (fp=0x65f520, data=<optimized out>, n=18446744073105506304) at fileops.c:1391
#2  0x00007ffff20208d8 in __GI__IO_fread (buf=<optimized out>, size=size@entry=1, count=18446744073105506304, fp=0x65f520) at iofread.c:42
#3  0x00007ffff584d150 in fread (__stream=<optimized out>, __n=<optimized out>, __size=1, __ptr=<optimized out>) at /usr/include/bits/stdio2.h:295
#4  Mat_VarReadNextInfo4 (mat=mat@entry=0x65b780) at mat4.c:314
#5  0x00007ffff584df78 in Mat_Open (matname=0x7fffffffac40 "cam_hat.jpg", mode=mode@entry=0) at mat.c:245
#6  0x00007ffff796411b in vips__mat_ismat (filename=<optimized out>) at matlab.c:303
#7  0x00007ffff7961ebd in vips_foreign_load_new_from_foreign_sub (load_class=0x65a400, filename=0x7fffffffac40 "cam_hat.jpg") at foreign.c:502
#8  0x00007ffff799cf85 in vips_slist_map2 (list=<optimized out>, fn=fn@entry=0x7ffff7961e90 <vips_foreign_load_new_from_foreign_sub>, a=a@entry=0x7fffffffac40, b=b@entry=0x0) at util.c:125
#9  0x00007ffff7961faa in vips_foreign_map (base=base@entry=0x7ffff79c2e36 "VipsForeignLoad", fn=fn@entry=0x7ffff7961e90 <vips_foreign_load_new_from_foreign_sub>, a=a@entry=0x7fffffffac40, b=b@entry=0x0) at foreign.c:446
#10 0x00007ffff7962598 in vips_foreign_find_load (filename=0x7fffffffac40 "cam_hat.jpg") at foreign.c:533
#11 0x00007ffff79625ec in vips_foreign_load_new_from_string (string=0x7fffffffac40 "cam_hat.jpg") at foreign.c:638
#12 0x00007ffff798cf40 in vips_object_new_from_string (object_class=0x656d10, p=p@entry=0x656a20 "cam_hat.jpg") at object.c:2052
#13 0x00007ffff7962f96 in vips_foreign_load_options (filename=filename@entry=0x656a20 "cam_hat.jpg", out=out@entry=0x7fffffffdd88) at foreign.c:1462
#14 0x00007ffff799199f in vips_image_build (object=<optimized out>) at image.c:681
#15 0x00007ffff798b2a9 in vips_object_build (object=0x6570c0) at object.c:179
#16 0x00007ffff7990d22 in vips_image_new_mode (filename=<optimized out>, mode=0x400a70 "rd") at image.c:1484
#17 0x00000000004009ce in main (argc=1, argv=0x7fffffffdf08) at vipsTest.c:5

Expected results:
The program should not crash.

Additional info:
I contacted John Cupitt, the author of VIPS, and he pointed out that this is due to a bug in libmatio's Mat_Open() which must be called to asses whether the file is compatible with libmatio. He recommended that I build VIPS with "./configure --without-matio ...". I think we should do this for the Fedora packages because, as a memory corruption error, this could give rise to a security vulnerability.
Comment 1 Benjamin Gilbert 2013-07-02 23:06:56 EDT
I'd rather see this fixed in libmatio, rather than disabling libmatio support in VIPS.
Comment 2 Benjamin Gilbert 2013-07-03 00:42:08 EDT
I've submitted a patch in the libmatio bugtracker: https://sourceforge.net/p/matio/bugs/16/
Comment 3 W. Michael Petullo 2013-07-03 12:16:25 EDT
There is also movement in VIPS since I first approached John. He changed the priority of the libmatio code so that it follows JPEG. This should be in 7.34.2, once released:


Of course, this won't completely remove the possibility of triggering the segfault, but it will reduce the liklihood by allowing other decoders to identify a file's format before making it to libmatio.
Comment 4 Benjamin Gilbert 2013-07-17 15:58:37 EDT
Should be fixed in this matio commit:


Reassigning to matio.
Comment 5 Fedora End Of Life 2015-01-09 13:37:16 EST
This message is a notice that Fedora 19 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 19. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained. Approximately 4 (four) weeks from now this bug will
be closed as EOL if it remains open with a Fedora 'version' of '19'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 19 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.
Comment 6 Fedora End Of Life 2015-02-17 10:47:42 EST
Fedora 19 changed to end-of-life (EOL) status on 2015-01-06. Fedora 19 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this

Thank you for reporting this bug and we are sorry it could not be fixed.

Note You need to log in before you can comment on or make changes to this bug.