diff options
author | Thomas Deutschmann <whissi@gentoo.org> | 2021-09-27 11:19:24 +0200 |
---|---|---|
committer | Thomas Deutschmann <whissi@gentoo.org> | 2021-10-20 18:22:47 +0200 |
commit | cc6be9c3577168805ec34b2d396e63361012282b (patch) | |
tree | 7dc794b08a1a6a786d540516c623cb1eebfb1863 /jbig2dec | |
parent | Import Ghostscript 9.54 (diff) | |
download | ghostscript-gpl-patches-cc6be9c3577168805ec34b2d396e63361012282b.tar.gz ghostscript-gpl-patches-cc6be9c3577168805ec34b2d396e63361012282b.tar.bz2 ghostscript-gpl-patches-cc6be9c3577168805ec34b2d396e63361012282b.zip |
Import Ghostscript 9.55ghostscript-9.55
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
Diffstat (limited to 'jbig2dec')
-rw-r--r-- | jbig2dec/README | 2 | ||||
-rw-r--r-- | jbig2dec/config_win32.h | 2 | ||||
-rw-r--r-- | jbig2dec/configure.ac.in | 1 | ||||
-rw-r--r-- | jbig2dec/jbig2.h | 5 | ||||
-rw-r--r-- | jbig2dec/jbig2_priv.h | 5 | ||||
-rw-r--r-- | jbig2dec/jbig2dec.1 | 2 | ||||
-rw-r--r-- | jbig2dec/jbig2dec.c | 112 |
7 files changed, 74 insertions, 55 deletions
diff --git a/jbig2dec/README b/jbig2dec/README index 7a0e53d2..1a739c69 100644 --- a/jbig2dec/README +++ b/jbig2dec/README @@ -28,5 +28,5 @@ Report bugs at https://bugs.ghostscript.com For security issues please use the "Security - Other" product, and for normal bugs the "jbig2dec" product. -Contact the developers at the IRC channel #ghostscript at freenode.net +Contact the developers on Discord or IRC at #ghostscript at libera.chat or via the mailing list <gs-devel@ghostscript.com>. diff --git a/jbig2dec/config_win32.h b/jbig2dec/config_win32.h index dc807c9a..53d4e918 100644 --- a/jbig2dec/config_win32.h +++ b/jbig2dec/config_win32.h @@ -44,7 +44,7 @@ typedef unsigned __int64 uint64_t; /* Previously we defined inline as nothing for 2005 and below */ # define inline #else -/* VS 2008 has __inline but not inline, later versiosn (unknown exactly where) define inline +/* VS 2008 has __inline but not inline, later versions (unknown exactly where) define inline * so cater for it being defined already. */ # if !(defined(inline)) diff --git a/jbig2dec/configure.ac.in b/jbig2dec/configure.ac.in index 95dbf639..cf3022f7 100644 --- a/jbig2dec/configure.ac.in +++ b/jbig2dec/configure.ac.in @@ -4,6 +4,7 @@ AC_INIT([jbig2dec], [unknown-version], [gs-devel@ghostscript.com]) AC_PREREQ(2.53) AC_CONFIG_SRCDIR([jbig2dec.c]) +AM_SILENT_RULES([yes]) AM_INIT_AUTOMAKE([-Wall]) AM_CONFIG_HEADER(config.h) diff --git a/jbig2dec/jbig2.h b/jbig2dec/jbig2.h index c83517e7..49fb1f02 100644 --- a/jbig2dec/jbig2.h +++ b/jbig2dec/jbig2.h @@ -105,11 +105,6 @@ void jbig2_release_page(Jbig2Ctx *ctx, Jbig2Image *image); /* mark the current page as complete, simulating an end-of-page segment (for broken streams) */ int jbig2_complete_page(Jbig2Ctx *ctx); -/* If we don't have a definition for inline, make it nothing so the code will compile */ -#ifndef inline -#define inline -#endif - #ifdef __cplusplus } #endif diff --git a/jbig2dec/jbig2_priv.h b/jbig2dec/jbig2_priv.h index ac341cdc..ed366af5 100644 --- a/jbig2dec/jbig2_priv.h +++ b/jbig2dec/jbig2_priv.h @@ -35,6 +35,11 @@ /* library internals */ +/* If we don't have a definition for inline, make it nothing so the code will compile */ +#ifndef inline +#define inline +#endif + typedef uint8_t byte; #define bool int diff --git a/jbig2dec/jbig2dec.1 b/jbig2dec/jbig2dec.1 index 70607eb8..b3a8e4be 100644 --- a/jbig2dec/jbig2dec.1 +++ b/jbig2dec/jbig2dec.1 @@ -69,7 +69,7 @@ Show usage summary. .SH REPORTING BUGS Report bugs at https://bugs.ghostscript.com -Contact the developers at the IRC channel #ghostscript at freenode.net +Contact the developers on Dicord and IRC on #ghostscript at libera.chat or via the mailing list <gs-devel@ghostscript.com>. .SH AUTHOR diff --git a/jbig2dec/jbig2dec.c b/jbig2dec/jbig2dec.c index 1a45e71d..dc1fd560 100644 --- a/jbig2dec/jbig2dec.c +++ b/jbig2dec/jbig2dec.c @@ -91,6 +91,47 @@ static int print_usage(void); #define KBYTE 1024 #define MBYTE (1024 * KBYTE) +static void *jbig2dec_reached_limit(jbig2dec_allocator_t *allocator, size_t oldsize, size_t size) +{ + size_t limit_mb = allocator->memory_limit / MBYTE; + size_t used_mb = allocator->memory_used / MBYTE; + size_t oldsize_mb = oldsize / MBYTE; + size_t size_mb = size / MBYTE; + + if (oldsize == 0) + jbig2_error(allocator->ctx, JBIG2_SEVERITY_FATAL, -1, "memory: limit reached: limit: %zu (%zu Mbyte) used: %zu (%zu Mbyte) allocation: %zu (%zu Mbyte)", + allocator->memory_limit, limit_mb, + allocator->memory_used, used_mb, + size, size_mb); + else + jbig2_error(allocator->ctx, JBIG2_SEVERITY_FATAL, -1, "memory: limit reached: limit: %zu (%zu Mbyte) used: %zu (%zu Mbyte) reallocation: %zu (%zu Mbyte) -> %zu (%zu Mbyte)", + allocator->memory_limit, limit_mb, + allocator->memory_used, used_mb, + oldsize, oldsize_mb, + size, size_mb); + + return NULL; +} + +static void jbig2dec_peak(jbig2dec_allocator_t *allocator) +{ + size_t limit_mb = allocator->memory_limit / MBYTE; + size_t peak_mb = allocator->memory_peak / MBYTE; + size_t used_mb = allocator->memory_used / MBYTE; + + if (allocator->ctx == NULL) + return; + if (used_mb <= peak_mb) + return; + + allocator->memory_peak = allocator->memory_used; + + jbig2_error(allocator->ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "memory: limit: %lu %sbyte used: %lu %sbyte, peak: %lu %sbyte", + limit_mb > 0 ? limit_mb : allocator->memory_limit, limit_mb > 0 ? "M" : "", + used_mb > 0 ? used_mb : allocator->memory_used, used_mb > 0 ? "M" : "", + peak_mb > 0 ? peak_mb : allocator->memory_peak, peak_mb > 0 ? "M" : ""); +} + static void *jbig2dec_alloc(Jbig2Allocator *allocator_, size_t size) { jbig2dec_allocator_t *allocator = (jbig2dec_allocator_t *) allocator_; @@ -98,24 +139,19 @@ static void *jbig2dec_alloc(Jbig2Allocator *allocator_, size_t size) if (size == 0) return NULL; - if (size > allocator->memory_limit - ALIGNMENT - allocator->memory_used) + if (size > SIZE_MAX - ALIGNMENT) return NULL; + if (size + ALIGNMENT > allocator->memory_limit - allocator->memory_used) + return jbig2dec_reached_limit(allocator, 0, size + ALIGNMENT); + ptr = malloc(size + ALIGNMENT); if (ptr == NULL) return NULL; memcpy(ptr, &size, sizeof(size)); allocator->memory_used += size + ALIGNMENT; - if (allocator->memory_used > allocator->memory_peak) { - allocator->memory_peak = allocator->memory_used; - - if (allocator->ctx) { - size_t limit_mb = allocator->memory_limit / MBYTE; - size_t peak_mb = allocator->memory_peak / MBYTE; - jbig2_error(allocator->ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "memory: limit: %lu Mbyte peak usage: %lu Mbyte", limit_mb, peak_mb); - } - } + jbig2dec_peak(allocator); return (unsigned char *) ptr + ALIGNMENT; } @@ -136,54 +172,36 @@ static void jbig2dec_free(Jbig2Allocator *allocator_, void *p) static void *jbig2dec_realloc(Jbig2Allocator *allocator_, void *p, size_t size) { jbig2dec_allocator_t *allocator = (jbig2dec_allocator_t *) allocator_; - unsigned char *oldp = p ? (unsigned char *) p - ALIGNMENT : NULL; + unsigned char *oldp; + size_t oldsize; - if (size > SIZE_MAX - ALIGNMENT) + if (p == NULL) + return jbig2dec_alloc(allocator_, size); + if (p < (void *) ALIGNMENT) return NULL; - if (oldp == NULL) - { - if (size == 0) - return NULL; - if (size > allocator->memory_limit - ALIGNMENT - allocator->memory_used) - return NULL; - - p = malloc(size + ALIGNMENT); + if (size == 0) { + jbig2dec_free(allocator_, p); + return NULL; } - else - { - size_t oldsize; - memcpy(&oldsize, oldp, sizeof(oldsize)); - - if (size == 0) - { - allocator->memory_used -= oldsize + ALIGNMENT; - free(oldp); - return NULL; - } + if (size > SIZE_MAX - ALIGNMENT) + return NULL; - if (size > allocator->memory_limit - allocator->memory_used + oldsize) - return NULL; + oldp = (unsigned char *) p - ALIGNMENT; + memcpy(&oldsize, oldp, sizeof(oldsize)); - p = realloc(oldp, size + ALIGNMENT); - if (p == NULL) - return NULL; + if (size + ALIGNMENT > allocator->memory_limit - allocator->memory_used + oldsize + ALIGNMENT) + return jbig2dec_reached_limit(allocator, oldsize + ALIGNMENT, size + ALIGNMENT); - allocator->memory_used -= oldsize + ALIGNMENT; - } + p = realloc(oldp, size + ALIGNMENT); + if (p == NULL) + return NULL; + allocator->memory_used -= oldsize + ALIGNMENT; memcpy(p, &size, sizeof(size)); allocator->memory_used += size + ALIGNMENT; - if (allocator->memory_used > allocator->memory_peak) { - allocator->memory_peak = allocator->memory_used; - - if (allocator->ctx) { - size_t limit_mb = allocator->memory_limit / MBYTE; - size_t peak_mb = allocator->memory_peak / MBYTE; - jbig2_error(allocator->ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "memory: limit: %lu Mbyte peak usage: %lu Mbyte", limit_mb, peak_mb); - } - } + jbig2dec_peak(allocator); return (unsigned char *) p + ALIGNMENT; } |