Commit Graph

1157 Commits

Author SHA1 Message Date
Tobias Stoeckmann fe7ae79084 Prevent OOB read with large file support on 32 bit
If imlib2 is compiled with large file support on 32 bit systems, which
is not the default, the TGA loader is vulnerable to an out of boundary
read due to insufficient off_t/size_t validations.

If large file support is enabled, off_t is 64 bit, while size_t is the
regular 32 bit on 32 bit architectures. Casting directly leads to issues
with files which are larger than 4 GB.

As it's unlikely to encounter such files, they will be simply ignored
on such systems.

64 bit systems are not affected.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2017-03-25 07:21:49 +01:00
Tobias Stoeckmann d5ebec2948 Properly release resources on error path
The code did not properly release resources in some error paths,
leading to memory leaks or possible double free issues.

If an image could not be loaded, some code paths check if width is 0
to determine if an error occurred. Therefore, always set width to 0
in such cases.
2017-03-12 09:52:02 +01:00
Tobias Stoeckmann 993911b6e5 Avoid out of boundary operations while parsing xpm
It is possible to trigger out of boundary read and write accesses while
parsing XPM files.

1. If the color definition is shorter than the specified cpp, i.e.
   characters per pixel, an out of boundary write can be triggered.
   The write will modify stack memory and could therefore be used to
   corrupt local variables or return addresses.
2. If the pixel area contains less than the required amount of
   characters per pixel, an out of boundary read can be triggered.
   This affects files with more than one character per pixel.
3. If an out of memory condition occurs, a null pointer dereference can
   be triggered because the variable line is reallocated if not enough
   memory was available. Dereferencing line with an offset would lead
   to yet another out of boundary write, which will lead to a
   segmentation fault on almost every system out there.
2017-02-20 21:03:36 +01:00
Kim Woelders 1f96129e2c Fix missing break.
Found by gcc 7:

grab.c: In function ‘__imlib_GrabXImageToRGBA’:
grab.c:85:14: error: this statement may fall through [-Werror=implicit-fallthrough=]
              for (y = 0; y < h; y++)
              ^~~
grab.c:97:11: note: here
           case 24:
           ^~~~
2017-02-12 20:43:53 +01:00
Kim Woelders f6d902efd9 PNM loader: Fix reading PNM bitmaps.
Attempting to read a PNM bitmap (ASCII format) would cause a lockup due
to infinite loop, and in certain cases write access outside allocated
memory.

Fixes CVE-2016-6348 (out-of-bounds writes ... presumably - CVE text not
disclosed yet).
Found by Neelima Krishnan, Intel Corporation.
2016-09-03 10:53:11 +02:00
Kim Woelders 9780f8dbc4 1.4.9. 2016-04-29 19:29:37 +02:00
Kim Woelders a0259d5181 Fix various potential OOM crashes.
There were several potential OOM crashes in __imlib_ListFilters(),
__imlib_ListLoaders() and __imlib_TrimLoaderList().

The fix of __imlib_TrimLoaderList() is from patch by
Yuriy M. Kaminskiy <yumkam@gmail.com>.
2016-04-16 17:35:08 +02:00
Kim Woelders 5b54980364 Move __imlib_ItemInList() to file.c.
It may not be the ideal location but it's better than image.c
2016-04-16 16:58:15 +02:00
Kim Woelders 31a261ac37 Trivial file function cleanups. 2016-04-15 22:05:22 +02:00
Kim Woelders b49e71ed77 Eliminate pImlibExternalFilter type. 2016-04-15 22:00:01 +02:00
Kim Woelders bdd7630a21 Make a number of functions static. 2016-04-15 21:59:52 +02:00
Yuriy M. Kaminskiy 633a8667b1 Harden API and internals against overly large images
Prevents potential integer overflow -> insufficient allocation -> heap overflow scenarios.
2016-04-13 22:21:58 +02:00
Alexander Smirnov 7836d83951 Fix cross-endianness for masks (1-bit depth images)
Summary:
Imlib generates masks on the client side with the bit order
of the client. Set this bit order for produced XImages.

Reviewers: kwo

Differential Revision: https://phab.enlightenment.org/D3891
2016-04-13 22:10:10 +02:00
Yuriy M. Kaminskiy ecfe46cc4a loader_xpm: remove nonsense/impossible/broken condition
1) ptr is DATA32 *, so (ptr-im->data) is (w * h) at most;
so this condition was broken, it should've been ((ptr-im->data) >= w*h);
2) ... however, ptr != NULL and (context > 1) are only possible together,
and ptr and count are incremented always together too, so
there are no point to check both; leave only less expensive check.
2016-04-12 20:00:56 +02:00
Yuriy M. Kaminskiy 7eba2e4c8a Fix integer overflow resulting in insufficient heap allocation
IMAGE_DIMENSIONS_OK ensures that image width and height are less then
46340, so that maximum number of pixels is ~2**31.

Unfortunately, there are a lot of code that allocates image data with
something like

   malloc(w * h * sizeof(DATA32));

Obviously, on 32-bit machines this results in integer overflow,
insufficient heap allocation, with [massive] out-of-bounds heap
overwrite.
Either X_MAX should be reduced to 32767, or (w)*(h) should be checked to
not exceed ULONG_MAX/sizeof(DATA32).

Security implications:
*) for 32-bit machines: insufficient heap allocation and heap overwrite
in many image loaders, with escalation potential to remote code
execution;
*) for 64-bit machines: it seems, no impact.
2016-04-09 14:54:46 +02:00
Kim Woelders c94d83ccab Fix potential divide-by-zero in imlib_image_draw_ellipse().
Attempting to draw a 2x1 ellipse with e.g. imlib_image_draw_ellipse(x, y, 2, 1)
causes a divide-by-zero.
It seems happy enough to draw 1x1, 1x2 and 2x2, but not 2x1.

Patch by Simon Lees.

https://bugs.debian.org/639414
2016-04-07 20:24:32 +02:00
Kim Woelders a8ca99a2a4 GIF loader: Indent.
And remove now unused label "finish".
2016-04-07 20:20:47 +02:00
Kim Woelders 1efd421614 GIF loader: Reduce progress checks from per-pixel to per-row.
Patch by Yuriy M. Kaminskiy.
2016-04-07 20:20:47 +02:00
Kim Woelders bfa12b68fe GIF loader: Remove check made redundant by previous commit.
Patch by Yuriy M. Kaminskiy.
2016-04-07 20:20:47 +02:00
Kim Woelders 37a9680166 GIF loader: Fix out-of-bound reads from colormap.
Bug-Debian: http://bugs.debian.org/785369
Note: removes all special-casing from the inner loop, optimize for common case.
Author: Yuriy M. Kaminskiy <yumkam+debian@gmail.com>
Reported-By: Jakub Wilk <jwilk@debian.org>

Thanks to Bernhard U:belacker <bernhardu@vr-web.de> for analysis.
2016-04-07 20:20:47 +02:00
Kim Woelders 5b5544ab77 Revert "gif: fix oob reads w/bad colormaps"
This reverts commit 16de244bd0.

Will push alternative solution.
2016-04-07 20:20:47 +02:00
Kim Woelders ce94edca1c Fix off-by-one OOB read in __imlib_MergeUpdate().
Patch by Yuriy M. Kaminskiy.

https://bugs.debian.org/819818
2016-04-06 02:36:23 +02:00
Bernhard Übelacker 16de244bd0 gif: fix oob reads w/bad colormaps
Verify the color map is inbounds before indexing with it.

https://bugs.debian.org/785369
2016-04-02 16:25:35 -04:00
Kim Woelders c0747f9fc9 Fix some "variable might be clobbered" warnings. 2016-03-21 09:16:44 +01:00
Kim Woelders 078fadde02 Fix some "variable set but not used" warnings. 2016-03-21 09:16:35 +01:00
Kim Woelders 94a357482b Fix "assuming signed overflow does not occur" warning. 2016-03-21 09:16:24 +01:00
Kim Woelders 8abdb98965 1.4.8. 2016-03-12 08:50:32 +01:00
Quentin Rameau 81fefc5785 Fix zlib loader filename check
Do not impose an arbitrary small buffer size limit on filenames when
checking and trimming gz extension.
2016-02-09 16:46:46 +01:00
Quentin Rameau bbde5efdc0 Fix bz2 loader filename check
Do not impose an arbitrary small buffer size limit on filenames when
checking and trimming bz2 extension.
2016-02-09 16:46:43 +01:00
Kim Woelders 93e6176764 Indent. 2016-02-07 08:08:00 +01:00
FRIGN 5cabf38155 Add a Farbfeld loader
(http://tools.suckless.org/farbfeld)
2016-02-07 08:01:40 +01:00
Kim Woelders e971fdcc20 Add compile to MAINTAINERCLEANFILES. 2015-11-01 15:17:56 +01:00
Kim Woelders bc35a1f7aa Remove redundant config.h. 2015-11-01 15:17:34 +01:00
Chloe Kudryavtsev 521573be21 add time.h include to common.h for time_t 2015-11-01 15:04:53 +01:00
Kim Woelders d242d589bb 1.4.7. 2015-04-04 20:08:21 +02:00
Kim Woelders 43e54dd31b Generate a ChangeLog using git shortlog between existing tags. 2015-04-04 20:08:20 +02:00
Kim Woelders ec1b4319b8 Indent the remaining unindented files. 2014-12-20 17:02:11 +01:00
Kim Woelders e20587d7a7 Enable visibility hiding by default. 2014-12-20 10:35:28 +01:00
Kim Woelders 98cec42013 Remove __hidden.
Going to to set -fvisibility=hidden (as default) shortly...
2014-12-20 10:35:28 +01:00
Kim Woelders cd902be360 Don't include Imlib2.h indirectly via image.h.
Also avoid using EAPI internally (requiring Imlib2.h).
2014-12-20 10:35:28 +01:00
Kim Woelders 3a121573f3 Indent. 2014-12-20 10:35:28 +01:00
Kim Woelders 54594ccd8d Change a number of internal function names.
Consistenly use the __-prefix on internal imlib_... functions.
2014-12-16 20:35:37 +01:00
Kim Woelders a4dd5bcdc2 Autofoo macro cleanups (ac_->ec_).
- Changes names AC_/ac_ to EC_/ec_ to stay out of autoconf namespace.
2014-12-16 20:30:48 +01:00
Kim Woelders a085694ff0 Autofoo update (AC_PROG_LIBTOOL -> LT_INIT). 2014-12-16 20:30:37 +01:00
Kim Woelders 4350b08dfe BMP loader: Simplify pixel fetch.
No need to go though elaborate API call (imlib_image_query_pixel()).
2014-12-16 20:04:58 +01:00
Kim Woelders 7b7d1aaf7b JPEG loader: Fix load() return code when only reading header.
Also simplify exit/error handling.
2014-12-16 20:03:28 +01:00
Kim Woelders 534f6c42a3 Revert "loader_gif(): Abort gif parsing if DGifGetLine() fails"
This reverts commit 2c6a3af9b6.

The fix breaks loading of certain images that at least apparently were
loaded just fine before.
2014-12-16 19:56:00 +01:00
Kim Woelders 55ddd412c3 Revert "__imlib_LoadImage(): Additionally check loader_ret to detect loader failures"
This reverts commit a104e317ce.

Breaks image loading in certain situations.

It seems that some loaders may return 0 even when load() "succeeds".

This appears to happen with the jpeg loader when not loading data
immediately (but only reading the header).
In this case jpeg_finish_decompress() exits via _JPEGFatalErrorHandler()
-> longjmp() causing the return code to be 0.

The fix reverted here is probably basically correct, but it will have to
wait until the loaders are fixed to behave properly.
2014-12-14 20:27:39 +01:00
Fabian Keil 0c34e1bfe2 load_gif: Make sure rows isn't used partly unitialized
Prevents:

==22831== Conditional jump or move depends on uninitialised value(s)
==22831==    at 0x634F040: load (loader_gif.c:181)
==22831==    by 0x1F7D7B3: __imlib_LoadImage (image.c:1041)
==22831==    by 0x1F090E4: imlib_load_image_with_error_return (api.c:1299)
==22831==    by 0x40F47B: feh_load_image (imlib.c:252)
==22831==    by 0x42CA0E: winwidget_loadimage (winwidget.c:753)
==22831==    by 0x42C918: winwidget_create_from_file (winwidget.c:126)
==22831==    by 0x421869: init_slideshow_mode (slideshow.c:62)
==22831==    by 0x418F13: main (main.c:78)
==22831==
==22831== Use of uninitialised value of size 8
==22831==    at 0x634F0F4: load (loader_gif.c:190)
==22831==    by 0x1F7D7B3: __imlib_LoadImage (image.c:1041)
==22831==    by 0x1F090E4: imlib_load_image_with_error_return (api.c:1299)
==22831==    by 0x40F47B: feh_load_image (imlib.c:252)
==22831==    by 0x42CA0E: winwidget_loadimage (winwidget.c:753)
==22831==    by 0x42C918: winwidget_create_from_file (winwidget.c:126)
==22831==    by 0x421869: init_slideshow_mode (slideshow.c:62)
==22831==    by 0x418F13: main (main.c:78)
==22831==
==22831== Use of uninitialised value of size 8
==22831==    at 0x634F122: load (loader_gif.c:191)
==22831==    by 0x1F7D7B3: __imlib_LoadImage (image.c:1041)
==22831==    by 0x1F090E4: imlib_load_image_with_error_return (api.c:1299)
==22831==    by 0x40F47B: feh_load_image (imlib.c:252)
==22831==    by 0x42CA0E: winwidget_loadimage (winwidget.c:753)
==22831==    by 0x42C918: winwidget_create_from_file (winwidget.c:126)
==22831==    by 0x421869: init_slideshow_mode (slideshow.c:62)
==22831==    by 0x418F13: main (main.c:78)
==22831==
==22831== Use of uninitialised value of size 8
==22831==    at 0x634F151: load (loader_gif.c:192)
==22831==    by 0x1F7D7B3: __imlib_LoadImage (image.c:1041)
==22831==    by 0x1F090E4: imlib_load_image_with_error_return (api.c:1299)
==22831==    by 0x40F47B: feh_load_image (imlib.c:252)
==22831==    by 0x42CA0E: winwidget_loadimage (winwidget.c:753)
==22831==    by 0x42C918: winwidget_create_from_file (winwidget.c:126)
==22831==    by 0x421869: init_slideshow_mode (slideshow.c:62)
==22831==    by 0x418F13: main (main.c:78)
==22831==

when opening id:000001,orig:smaller-animated.gif with feh.
2014-12-06 13:58:35 +09:00
Fabian Keil 60779351df imlib_save_image_with_error_return(): Check loader return code to prevent use of unitialized memor 2014-12-06 13:57:14 +09:00