FLTK logo

STR #2296

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]
 

Return to Bugs & Features | Roadmap 2.0 | Post Text | Post File | SVN ⇄ GIT ]

STR #2296

Application:FLTK Library
Status:5 - New
Priority:4 - High, e.g. key functionality not working
Scope:3 - Applies to all machines and operating systems
Subsystem:Unassigned
Summary:segmentation fault when fetching jpeg images from data
Version:2.0-current
Created By:bebopfreak
Assigned To:Unassigned
Fix Version:Unassigned
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:

Post File ]
Name/Time/Date Filename/Size  
 
#1 bgbnbigben
00:44 Jul 12, 2010
jpegpatch.patch
0k
 
 
#2 bebopfreak
04:48 Jul 12, 2010
fl_jpeg.cxx.gz
5k
 
 
#3 bgbnbigben
05:11 Jul 12, 2010
jpegpatch2.patch
5k
 
     

Trouble Report Comments:

Post Text ]
Name/Time/Date Text  
 
#1 bebopfreak
01:10 Dec 09, 2009
fill_input_buffer in images/fl_jpeg.cxx segfaults (very seldom)

As there is no length check on the data, I get two error types with
valgrind:
- memcpy overlaps (might not be that serious)
- invalid read, which is sort of critical

One should check at least for EOI markers to avoid some error conditions.

(tested with i386 (Ubuntu) and arm (Nokia N800) systems)
 
 
#2 bgbnbigben
00:44 Jul 12, 2010
so i could force the first problem with memcpy overlapping - i cant remember how though. Whilst "it might be not that serious", as far as i'm aware memcpy overlapping has undefined behaviour, so it is a little serious. :P

If you could tell us how you managed to force the invalid read, that'd be good......
 
 
#3 matt
01:06 Jul 12, 2010
memcpy() does not check for overlapping, however memmove() does. Simply replace the first with the second.  
 
#4 bgbnbigben
01:38 Jul 12, 2010
yup, that's all the patch does.

It's probably a good idea to keep it here though. It's a simple fix for possibly undefined behavior, so it can't hurt.
 
 
#5 bebopfreak
04:57 Jul 12, 2010
I couldn't write a testprogram that would reproducibly yield the error, but the error occurred reliably after some time (lots of jpegs loaded from the internet and lots of memory management, altogether not very deterministic).
I added a modified version of fl_jpeg.cxx, which tries to compute the length of the jpeg data.
As a result, the errors were gone!
But this patch isn't safe either - the only way would be to know the length.
 
 
#6 bgbnbigben
04:59 Jul 12, 2010
From what I could tell, that patch saves the invalid read.
I think between your patch and mine, we should be about right. :P

Unfortunately, I don't know of a way to load the length of a jpeg file.
I'll post the svn diff of your file and mine together, and upload it again. Hopefully that'll be the last of this bug.
If you run across a file that forces an invalid read, be sure to send it along.
:)
 
 
#7 bgbnbigben
05:02 Jul 12, 2010
Out of curiosity, is there any need to keep the fprintf(stderr, ...) in your code, or can they be changed to xfprintf()s?  
 
#8 bebopfreak
05:18 Jul 12, 2010
forgot about the fprintfs -- as they didn't fire any more  
 
#9 bgbnbigben
05:26 Jul 12, 2010
Sure. I've left them in here, but if anyone wants to commit this to svn, feel free to throw out lines 120 to 133, and/or the xfprintf statements.

Is there any reason to keep this STR open now?
 
     

Return to Bugs & Features | Post Text | Post File ]

 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.