summaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-03-16 15:58:48 +0000
committerCaolán McNamara <caolanm@redhat.com>2017-03-17 23:36:10 +0000
commit2f1045a85970f2fc822f799a9a213fc533b740c2 (patch)
treef702a974ca9f4d48cac12432b42df5010ead4e33 /external
parentdac990d646461c2f5a44596d5fd6231e4462c987 (diff)
tweak libjpeg to honor JPEGMEM and set it in file format testers
Change-Id: I6660ccc68d3c82bf6118c2106a9293fd37e801ae Reviewed-on: https://gerrit.libreoffice.org/35283 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'external')
-rw-r--r--external/jpeg-turbo/UnpackedTarball_jpeg-turbo.mk1
-rw-r--r--external/jpeg-turbo/jpeg-turbo.limits.patch.146
2 files changed, 47 insertions, 0 deletions
diff --git a/external/jpeg-turbo/UnpackedTarball_jpeg-turbo.mk b/external/jpeg-turbo/UnpackedTarball_jpeg-turbo.mk
index 5fdc5e4cc8d1..222ce407f1a3 100644
--- a/external/jpeg-turbo/UnpackedTarball_jpeg-turbo.mk
+++ b/external/jpeg-turbo/UnpackedTarball_jpeg-turbo.mk
@@ -18,6 +18,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,jpeg-turbo,\
$(if $(filter WNT,$(OS)),external/jpeg-turbo/jpeg-turbo.win_build.patch.1) \
external/jpeg-turbo/jpeg-turbo.arm_build.patch.1 \
external/jpeg-turbo/ubsan.patch \
+ external/jpeg-turbo/jpeg-turbo.limits.patch.1 \
))
# vim: set noet sw=4 ts=4:
diff --git a/external/jpeg-turbo/jpeg-turbo.limits.patch.1 b/external/jpeg-turbo/jpeg-turbo.limits.patch.1
new file mode 100644
index 000000000000..f78fd4b3253a
--- /dev/null
+++ b/external/jpeg-turbo/jpeg-turbo.limits.patch.1
@@ -0,0 +1,46 @@
+From 066fee2e7d6834f24838bc1896aa38ca77209e3c Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
+Date: Thu, 16 Mar 2017 15:53:53 +0000
+Subject: [PATCH] honor max_memory_to_use if its set
+
+I'd like to use JPEGMEM to limit memory that libjpeg will allocation
+to reject sizes that would the default 2G limit under asan while
+fuzzing LibreOffice's jpeg integration
+---
+ jmemnobs.c | 14 ++++++++++++--
+ 1 file changed, 12 insertions(+), 2 deletions(-)
+
+diff --git a/jmemnobs.c b/jmemnobs.c
+index 5797198..c7dc560 100644
+--- a/jmemnobs.c
++++ b/jmemnobs.c
+@@ -66,14 +66,24 @@ jpeg_free_large (j_common_ptr cinfo, void *object, size_t sizeofobject)
+
+ /*
+ * This routine computes the total memory space available for allocation.
+- * Here we always say, "we got all you want bud!"
+ */
+
+ GLOBAL(size_t)
+ jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed,
+ size_t max_bytes_needed, size_t already_allocated)
+ {
+- return max_bytes_needed;
++ if (!cinfo->mem->max_memory_to_use)
++ {
++ /* Here we always say, "we got all you want bud!" */
++ return max_bytes_needed;
++ }
++
++ if (cinfo->mem->max_memory_to_use - already_allocated >= max_bytes_needed)
++ {
++ return max_bytes_needed;
++ }
++
++ return cinfo->mem->max_memory_to_use - already_allocated;
+ }
+
+
+--
+2.9.3
+