shithub: jbig2

Download patch

ref: a8ed5c84b32c0ba67d1b12a4f4d0a1099d2cf1fa
parent: 12c1455891de226bf93235fc4469f670d08c9b94
author: Sebastian Rasmussen <[email protected]>
date: Wed Apr 10 14:23:26 EDT 2019

jbig2dec: Check that header version matches library version.

--- a/jbig2.c
+++ b/jbig2.c
@@ -100,9 +100,18 @@
 }
 
 Jbig2Ctx *
-jbig2_ctx_new(Jbig2Allocator *allocator, Jbig2Options options, Jbig2GlobalCtx *global_ctx, Jbig2ErrorCallback error_callback, void *error_callback_data)
+jbig2_ctx_new_imp(Jbig2Allocator *allocator, Jbig2Options options, Jbig2GlobalCtx *global_ctx, Jbig2ErrorCallback error_callback, void *error_callback_data, int jbig2_version_major, int jbig2_version_minor)
 {
     Jbig2Ctx *result;
+
+    if (jbig2_version_major != JBIG2_VERSION_MAJOR || jbig2_version_minor != JBIG2_VERSION_MINOR) {
+        Jbig2Ctx fakectx;
+        fakectx.error_callback = error_callback;
+        fakectx.error_callback_data = error_callback_data;
+        jbig2_error(&fakectx, JBIG2_SEVERITY_FATAL, -1, "incompatible jbig2dec header (%d.%d) and library (%d.%d) versions",
+            jbig2_version_major, jbig2_version_minor, JBIG2_VERSION_MAJOR, JBIG2_VERSION_MINOR);
+        return NULL;
+    }
 
     if (allocator == NULL)
         allocator = &jbig2_default_allocator;
--- a/jbig2.h
+++ b/jbig2.h
@@ -80,8 +80,14 @@
 };
 
 /* decoder context */
-Jbig2Ctx *jbig2_ctx_new(Jbig2Allocator *allocator,
-                        Jbig2Options options, Jbig2GlobalCtx *global_ctx, Jbig2ErrorCallback error_callback, void *error_callback_data);
+#define jbig2_ctx_new(allocator, options, global_ctx, error_callback, error_callback_data) jbig2_ctx_new_imp((allocator), (options), (global_ctx), (error_callback), (error_callback_data), JBIG2_VERSION_MAJOR, JBIG2_VERSION_MINOR)
+Jbig2Ctx *jbig2_ctx_new_imp(Jbig2Allocator *allocator,
+                        Jbig2Options options,
+                        Jbig2GlobalCtx *global_ctx,
+                        Jbig2ErrorCallback error_callback,
+                        void *error_callback_data,
+                        int jbig2_version_major,
+                        int jbig2_version_minor);
 Jbig2Allocator *jbig2_ctx_free(Jbig2Ctx *ctx);
 
 /* global context for embedded streams */