shithub: jbig2

Download patch

ref: 653ead574230a4458e55eeee9d863abc9d73e09f
parent: 2ca3c0076b48c7f40b457fff027388e2329281c8
author: Sebastian Rasmussen <[email protected]>
date: Tue Jun 19 19:16:17 EDT 2018

jbig2dec: Remove untested, incomplete metadata handling.

--- a/Makefile.am
+++ b/Makefile.am
@@ -21,7 +21,7 @@
 	jbig2_arith.h jbig2_arith_iaid.h jbig2_arith_int.h \
 	jbig2_huffman.h jbig2_hufftab.h jbig2_mmr.h \
 	jbig2_generic.h jbig2_symbol_dict.h jbig2_text.h \
-	jbig2_metadata.c jbig2_metadata.h memento.c memento.h
+	memento.c memento.h
 
 bin_PROGRAMS = jbig2dec
 noinst_PROGRAMS = test_sha1 test_huffman test_arith
--- a/Makefile.unix
+++ b/Makefile.unix
@@ -10,13 +10,12 @@
 	jbig2_arith.c jbig2_arith_int.c jbig2_arith_iaid.c \
 	jbig2_huffman.c jbig2_segment.c jbig2_page.c jbig2_symbol_dict.c \
 	jbig2_text.c jbig2_halftone.c jbig2_generic.c jbig2_refinement.c \
-	jbig2_mmr.c jbig2_image.c jbig2_metadata.c jbig2.c
+	jbig2_mmr.c jbig2_image.c jbig2.c
 LIB_OBJS := $(LIB_SRCS:%.c=%.o)
 LIB_HDRS := \
 	jbig2.h jbig2_arith.h jbig2_arith_iaid.h jbig2_arith_int.h \
 	jbig2_generic.h jbig2_huffman.h jbig2_hufftab.h jbig2_image.h \
-	jbig2_metadata.h jbig2_mmr.h jbig2_priv.h jbig2_symbol_dict.h \
-	jbig2_text.h os_types.h
+	jbig2_mmr.h jbig2_priv.h jbig2_symbol_dict.h jbig2_text.h os_types.h
 
 APP_SRCS := jbig2_image_pbm.c jbig2_image_png.c jbig2dec.c sha1.c
 APP_OBJS := $(APP_SRCS:%.c=%.o)
--- a/jbig2_metadata.c
+++ /dev/null
@@ -1,190 +1,0 @@
-/* Copyright (C) 2001-2018 Artifex Software, Inc.
-   All Rights Reserved.
-
-   This software is provided AS-IS with no warranty, either express or
-   implied.
-
-   This software is distributed under license and may not be copied,
-   modified or distributed except as expressly authorized under the terms
-   of the license contained in the file LICENSE in this distribution.
-
-   Refer to licensing information at http://www.artifex.com or contact
-   Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
-   CA 94945, U.S.A., +1(415)492-9861, for further information.
-*/
-
-/*
-    jbig2dec
-*/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "os_types.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "jbig2.h"
-#include "jbig2_priv.h"
-#include "jbig2_metadata.h"
-#include "jbig2_image.h"
-#include "jbig2_segment.h"
-
-/* metadata key,value list object */
-Jbig2Metadata *
-jbig2_metadata_new(Jbig2Ctx *ctx, Jbig2Encoding encoding)
-{
-    Jbig2Metadata *md = jbig2_new(ctx, Jbig2Metadata, 1);
-
-    if (md != NULL) {
-        md->encoding = encoding;
-        md->entries = 0;
-        md->max_entries = 4;
-        md->keys = jbig2_new(ctx, char *, md->max_entries);
-        md->values = jbig2_new(ctx, char *, md->max_entries);
-
-        if (md->keys == NULL || md->values == NULL) {
-            jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate storage for metadata keys/values");
-            jbig2_metadata_free(ctx, md);
-            md = NULL;
-        }
-    } else {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate storage for metadata");
-    }
-    return md;
-}
-
-void
-jbig2_metadata_free(Jbig2Ctx *ctx, Jbig2Metadata *md)
-{
-    int i;
-
-    if (md == NULL)
-        return;
-
-    if (md->keys) {
-        /* assume we own the pointers */
-        for (i = 0; i < md->entries; i++)
-            jbig2_free(ctx->allocator, md->keys[i]);
-        jbig2_free(ctx->allocator, md->keys);
-    }
-    if (md->values) {
-        for (i = 0; i < md->entries; i++)
-            jbig2_free(ctx->allocator, md->values[i]);
-        jbig2_free(ctx->allocator, md->values);
-    }
-    jbig2_free(ctx->allocator, md);
-}
-
-static char *
-jbig2_strndup(Jbig2Ctx *ctx, const char *c, const int len)
-{
-    char *s = jbig2_new(ctx, char, len);
-
-    if (s == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to duplicate comment string");
-    } else {
-        memcpy(s, c, len);
-    }
-    return s;
-}
-
-static int
-jbig2_metadata_add(Jbig2Ctx *ctx, Jbig2Metadata *md, const char *key, const int key_length, const char *value, const int value_length)
-{
-    char **keys, **values;
-
-    /* grow the array if necessary */
-    if (md->entries == md->max_entries) {
-        md->max_entries <<= 1;
-        keys = jbig2_renew(ctx, md->keys, char *, md->max_entries);
-        values = jbig2_renew(ctx, md->values, char *, md->max_entries);
-
-        if (keys == NULL || values == NULL)
-            return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to resize metadata structure");
-        md->keys = keys;
-        md->values = values;
-    }
-
-    /* copy the passed key,value pair */
-    md->keys[md->entries] = jbig2_strndup(ctx, key, key_length);
-    md->values[md->entries] = jbig2_strndup(ctx, value, value_length);
-    if (md->keys[md->entries] == NULL || md->values[md->entries] == NULL) {
-        return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to accommodate more metadata");
-    }
-    md->entries++;
-
-    return 0;
-}
-
-/* decode an ascii comment segment 7.4.15.1 */
-int
-jbig2_comment_ascii(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data)
-{
-    char *s, *end;
-    Jbig2Metadata *comment;
-    char *key, *value;
-    int code;
-    char *p;
-
-    jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "ASCII comment data");
-
-    s = (char *)(segment_data + 4);
-    end = (char *)(segment_data + segment->data_length);
-
-    comment = jbig2_metadata_new(ctx, JBIG2_ENCODING_ASCII);
-    if (comment == NULL)
-        return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to allocate comment structure");
-
-    /* loop over the segment data pulling out the key,value pairs */
-    while (s < end && *s) {
-        key = s;
-        value = memchr(key, '\0', end - key);
-        if (!value)
-            goto too_short;
-        value++;
-        s = memchr(value, '\0', end - value);
-        if (!s)
-            goto too_short;
-        s++;
-
-        p = key;
-        while (*p) {
-            if (*p > 127)
-                goto invalid_character;
-            p++;
-        }
-        p = value;
-        while (*p) {
-            if (*p > 127)
-                goto invalid_character;
-            p++;
-        }
-
-        code = jbig2_metadata_add(ctx, comment, key, value - key, value, s - value);
-        if (code < 0)
-            return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to add ascii comment data");
-        jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "'%s'\t'%s'", key, value);
-    }
-
-    /* TODO: associate with ctx, page, or referred-to segment(s) */
-    segment->result = comment;
-
-    return 0;
-
-too_short:
-    jbig2_metadata_free(ctx, comment);
-    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "unexpected end of comment segment");
-
-invalid_character:
-    jbig2_metadata_free(ctx, comment);
-    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "invalid character 0x%02x found in ASCII comment", *p);
-}
-
-/* decode a UCS-16 comment segment 7.4.15.2 */
-int
-jbig2_comment_unicode(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data)
-{
-    return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unhandled unicode comment segment");
-}
--- a/jbig2_metadata.h
+++ /dev/null
@@ -1,46 +1,0 @@
-/* Copyright (C) 2001-2018 Artifex Software, Inc.
-   All Rights Reserved.
-
-   This software is provided AS-IS with no warranty, either express or
-   implied.
-
-   This software is distributed under license and may not be copied,
-   modified or distributed except as expressly authorized under the terms
-   of the license contained in the file LICENSE in this distribution.
-
-   Refer to licensing information at http://www.artifex.com or contact
-   Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
-   CA 94945, U.S.A., +1(415)492-9861, for further information.
-*/
-
-/*
-    jbig2dec
-*/
-
-#ifndef _JBIG2_METADATA_H
-#define _JBIG2_METADATA_H
-
-/* metadata from extension segments */
-
-/* these bits should be moved to jbig2.h for public access */
-typedef enum {
-    JBIG2_ENCODING_ASCII,
-    JBIG2_ENCODING_UCS16
-} Jbig2Encoding;
-
-typedef struct _Jbig2Metadata Jbig2Metadata;
-
-Jbig2Metadata *jbig2_metadata_new(Jbig2Ctx *ctx, Jbig2Encoding encoding);
-void jbig2_metadata_free(Jbig2Ctx *ctx, Jbig2Metadata *md);
-
-struct _Jbig2Metadata {
-    Jbig2Encoding encoding;
-    char **keys, * *values;
-    int entries, max_entries;
-};
-
-/* these bits can go to jbig2_priv.h */
-int jbig2_comment_ascii(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
-int jbig2_comment_unicode(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
-
-#endif /* _JBIG2_METADATA_H */
--- a/jbig2_segment.c
+++ b/jbig2_segment.c
@@ -33,7 +33,6 @@
 #include "jbig2_image.h"
 #include "jbig2_halftone.h"
 #include "jbig2_huffman.h"
-#include "jbig2_metadata.h"
 #include "jbig2_page.h"
 #include "jbig2_refinement.h"
 #include "jbig2_segment.h"
@@ -159,10 +158,6 @@
         if (segment->result != NULL)
             jbig2_table_free(ctx, (Jbig2HuffmanParams *) segment->result);
         break;
-    case 62:
-        if (segment->result != NULL)
-            jbig2_metadata_free(ctx, (Jbig2Metadata *) segment->result);
-        break;
     default:
         /* anything else is probably an undefined pointer */
         break;
@@ -229,9 +224,11 @@
 
     switch (type) {
     case 0x20000000:
-        return jbig2_comment_ascii(ctx, segment, segment_data);
+        jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "ignoring ASCII comment");
+        break;
     case 0x20000002:
-        return jbig2_comment_unicode(ctx, segment, segment_data);
+        jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "ignoring UCS-2 comment");
+        break;
     default:
         if (necessary) {
             return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "unhandled necessary extension segment type 0x%08x", type);
@@ -239,6 +236,8 @@
             return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unhandled extension segment");
         }
     }
+
+    return 0;
 }
 
 /* dispatch code for profile segment parsing */
--- a/msvc.mak
+++ b/msvc.mak
@@ -45,13 +45,11 @@
  jbig2_generic$(OBJ) jbig2_refinement$(OBJ) jbig2_halftone$(OBJ)\
  jbig2_image$(OBJ) jbig2_image_pbm$(OBJ) $(JBIG2_IMAGE_PNG_OBJ) \
  jbig2_segment$(OBJ) jbig2_symbol_dict$(OBJ) jbig2_text$(OBJ) \
- jbig2_mmr$(OBJ) jbig2_page$(OBJ) jbig2_metadata$(OBJ) \
- jbig2dec$(OBJ) sha1$(OBJ)
+ jbig2_mmr$(OBJ) jbig2_page$(OBJ) jbig2dec$(OBJ) sha1$(OBJ)
 
 HDRS=getopt.h jbig2.h jbig2_arith.h jbig2_arith_iaid.h jbig2_arith_int.h \
  jbig2_generic.h jbig2_huffman.h jbig2_hufftab.h jbig2_image.h \
- jbig2_mmr.h jbig2_priv.h jbig2_symbol_dict.h jbig2_metadata.h \
- config_win32.h sha1.h
+ jbig2_mmr.h jbig2_priv.h jbig2_symbol_dict.h config_win32.h sha1.h
 
 all: jbig2dec$(EXE)
 
@@ -111,9 +109,6 @@
 
 jbig2_text$(OBJ): jbig2_text.c $(HDRS)
 	$(CC) $(CFLAGS) -c jbig2_text.c
-
-jbig2_metadata$(OBJ): jbig2_metadata.c $(HDRS)
-	$(CC) $(CFLAGS) -c jbig2_metadata.c
 
 jbig2dec$(OBJ): jbig2dec.c $(HDRS)
 	$(CC) $(CFLAGS) -c jbig2dec.c