summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/image.h1
-rw-r--r--include/mupdf/fitz/xml.h4
-rw-r--r--source/fitz/image.c28
-rw-r--r--source/fitz/xml.c8
-rw-r--r--source/html/epub-doc.c16
-rw-r--r--source/html/html-layout.c6
-rw-r--r--source/svg/svg-doc.c6
-rw-r--r--source/xps/xps-doc.c4
-rw-r--r--source/xps/xps-glyphs.c15
-rw-r--r--source/xps/xps-image.c5
-rw-r--r--source/xps/xps-imp.h3
-rw-r--r--source/xps/xps-outline.c2
-rw-r--r--source/xps/xps-resource.c2
-rw-r--r--source/xps/xps-zip.c20
14 files changed, 32 insertions, 88 deletions
diff --git a/include/mupdf/fitz/image.h b/include/mupdf/fitz/image.h
index 49f05a1a..6ce71a14 100644
--- a/include/mupdf/fitz/image.h
+++ b/include/mupdf/fitz/image.h
@@ -78,7 +78,6 @@ typedef size_t (fz_image_get_size_fn)(fz_context *, fz_image *);
fz_image *fz_new_image(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace, int xres, int yres, int interpolate, int imagemask, float *decode, int *colorkey, fz_image *mask, int size, fz_image_get_pixmap_fn *get, fz_image_get_size_fn *get_size, fz_drop_image_fn *drop);
fz_image *fz_new_image_from_compressed_buffer(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace, int xres, int yres, int interpolate, int imagemask, float *decode, int *colorkey, fz_compressed_buffer *buffer, fz_image *mask);
fz_image *fz_new_image_from_pixmap(fz_context *ctx, fz_pixmap *pixmap, fz_image *mask);
-fz_image *fz_new_image_from_data(fz_context *ctx, unsigned char *data, size_t len);
fz_image *fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer);
fz_image *fz_new_image_from_file(fz_context *ctx, const char *path);
void fz_drop_image_imp(fz_context *ctx, fz_storable *image);
diff --git a/include/mupdf/fitz/xml.h b/include/mupdf/fitz/xml.h
index 35608fcc..caf5b3ba 100644
--- a/include/mupdf/fitz/xml.h
+++ b/include/mupdf/fitz/xml.h
@@ -11,11 +11,11 @@
typedef struct fz_xml_s fz_xml;
/*
- fz_parse_xml: Parse a zero-terminated string into a tree of xml nodes.
+ fz_parse_xml: Parse the contents of buffer into a tree of xml nodes.
preserve_white: whether to keep or delete all-whitespace nodes.
*/
-fz_xml *fz_parse_xml(fz_context *ctx, unsigned char *buf, size_t len, int preserve_white);
+fz_xml *fz_parse_xml(fz_context *ctx, fz_buffer *buf, int preserve_white);
/*
fz_xml_prev: Return previous sibling of XML node.
diff --git a/source/fitz/image.c b/source/fitz/image.c
index c7bbb3ad..1c806fcd 100644
--- a/source/fitz/image.c
+++ b/source/fitz/image.c
@@ -893,34 +893,6 @@ void fz_set_pixmap_image_tile(fz_context *ctx, fz_pixmap_image *image, fz_pixmap
}
fz_image *
-fz_new_image_from_data(fz_context *ctx, unsigned char *data, size_t len)
-{
- fz_buffer *buffer = NULL;
- fz_image *image;
-
- fz_var(buffer);
- fz_var(data);
-
- fz_try(ctx)
- {
- buffer = fz_new_buffer_from_data(ctx, data, len);
- data = NULL;
- image = fz_new_image_from_buffer(ctx, buffer);
- }
- fz_always(ctx)
- {
- fz_drop_buffer(ctx, buffer);
- }
- fz_catch(ctx)
- {
- fz_free(ctx, data);
- fz_rethrow(ctx);
- }
-
- return image;
-}
-
-fz_image *
fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer)
{
fz_compressed_buffer *bc;
diff --git a/source/fitz/xml.c b/source/fitz/xml.c
index d063ee33..a81ab66d 100644
--- a/source/fitz/xml.c
+++ b/source/fitz/xml.c
@@ -626,14 +626,18 @@ static char *convert_to_utf8(fz_context *doc, unsigned char *s, size_t n, int *d
}
fz_xml *
-fz_parse_xml(fz_context *ctx, unsigned char *s, size_t n, int preserve_white)
+fz_parse_xml(fz_context *ctx, fz_buffer *buf, int preserve_white)
{
struct parser parser;
fz_xml root, *node;
char *p, *error;
int dofree;
+ unsigned char *s;
+ size_t n;
- /* s is already null-terminated (see xps_new_part) */
+ /* ensure we are zero-terminated */
+ fz_terminate_buffer(ctx, buf);
+ n = fz_buffer_storage(ctx, buf, &s);
memset(&root, 0, sizeof(root));
parser.head = &root;
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c
index cf7f1ecf..d220816d 100644
--- a/source/html/epub-doc.c
+++ b/source/html/epub-doc.c
@@ -309,15 +309,11 @@ epub_parse_ncx(fz_context *ctx, epub_document *doc, const char *path)
fz_buffer *buf;
fz_xml *ncx;
char base_uri[2048];
- unsigned char *data;
- size_t len;
fz_dirname(base_uri, path, sizeof base_uri);
buf = fz_read_archive_entry(ctx, zip, path);
- fz_terminate_buffer(ctx, buf);
- len = fz_buffer_storage(ctx, buf, &data);
- ncx = fz_parse_xml(ctx, data, len, 0);
+ ncx = fz_parse_xml(ctx, buf, 0);
fz_drop_buffer(ctx, buf);
doc->outline = epub_parse_ncx_imp(ctx, doc, fz_xml_find_down(ncx, "navMap"), base_uri);
@@ -347,8 +343,6 @@ epub_parse_header(fz_context *ctx, epub_document *doc)
const char *version;
char ncx[2048], s[2048];
epub_chapter **tailp;
- size_t len;
- unsigned char *data;
if (fz_has_archive_entry(ctx, zip, "META-INF/rights.xml"))
fz_throw(ctx, FZ_ERROR_GENERIC, "EPUB is locked by DRM");
@@ -358,9 +352,7 @@ epub_parse_header(fz_context *ctx, epub_document *doc)
/* parse META-INF/container.xml to find OPF */
buf = fz_read_archive_entry(ctx, zip, "META-INF/container.xml");
- fz_terminate_buffer(ctx, buf);
- len = fz_buffer_storage(ctx, buf, &data);
- container_xml = fz_parse_xml(ctx, data, len, 0);
+ container_xml = fz_parse_xml(ctx, buf, 0);
fz_drop_buffer(ctx, buf);
container = fz_xml_find(container_xml, "container");
@@ -375,9 +367,7 @@ epub_parse_header(fz_context *ctx, epub_document *doc)
/* parse OPF to find NCX and spine */
buf = fz_read_archive_entry(ctx, zip, full_path);
- fz_terminate_buffer(ctx, buf);
- len = fz_buffer_storage(ctx, buf, &data);
- content_opf = fz_parse_xml(ctx, data, len, 0);
+ content_opf = fz_parse_xml(ctx, buf, 0);
fz_drop_buffer(ctx, buf);
package = fz_xml_find(content_opf, "package");
diff --git a/source/html/html-layout.c b/source/html/html-layout.c
index ff2102d1..76b4a1cf 100644
--- a/source/html/html-layout.c
+++ b/source/html/html-layout.c
@@ -2548,8 +2548,6 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha
{
fz_xml *xml;
fz_html *html;
- unsigned char *data;
- size_t len;
fz_css_match match;
struct genstate g;
@@ -2562,9 +2560,7 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha
g.emit_white = 0;
g.last_brk_cls = UCDN_LINEBREAK_CLASS_OP;
- fz_terminate_buffer(ctx, buf);
- len = fz_buffer_storage(ctx, buf, &data);
- xml = fz_parse_xml(ctx, data, len, 1);
+ xml = fz_parse_xml(ctx, buf, 1);
g.css = fz_new_css(ctx);
fz_try(ctx)
diff --git a/source/svg/svg-doc.c b/source/svg/svg-doc.c
index 06de56f5..bfd40065 100644
--- a/source/svg/svg-doc.c
+++ b/source/svg/svg-doc.c
@@ -88,12 +88,8 @@ svg_open_document_with_buffer(fz_context *ctx, fz_buffer *buf)
{
svg_document *doc;
fz_xml *root;
- size_t len;
- unsigned char *data;
- fz_terminate_buffer(ctx, buf);
- len = fz_buffer_storage(ctx, buf, &data);
- root = fz_parse_xml(ctx, data, len, 0);
+ root = fz_parse_xml(ctx, buf, 0);
doc = fz_new_document(ctx, svg_document);
doc->super.drop_document = svg_drop_document;
diff --git a/source/xps/xps-doc.c b/source/xps/xps-doc.c
index 8197f505..8f708bf7 100644
--- a/source/xps/xps-doc.c
+++ b/source/xps/xps-doc.c
@@ -276,7 +276,7 @@ xps_parse_metadata(fz_context *ctx, xps_document *doc, xps_part *part, xps_fixdo
doc->base_uri = buf;
doc->part_uri = part->name;
- root = fz_parse_xml(ctx, part->data, part->size, 0);
+ root = fz_parse_xml(ctx, part->data, 0);
xps_parse_metadata_imp(ctx, doc, root, fixdoc);
fz_drop_xml(ctx, root);
@@ -353,7 +353,7 @@ xps_load_fixed_page(fz_context *ctx, xps_document *doc, xps_fixpage *page)
part = xps_read_part(ctx, doc, page->name);
fz_try(ctx)
{
- root = fz_parse_xml(ctx, part->data, part->size, 0);
+ root = fz_parse_xml(ctx, part->data, 0);
}
fz_always(ctx)
{
diff --git a/source/xps/xps-glyphs.c b/source/xps/xps-glyphs.c
index 0ea1ab9d..98a44217 100644
--- a/source/xps/xps-glyphs.c
+++ b/source/xps/xps-glyphs.c
@@ -98,10 +98,13 @@ xps_deobfuscate_font_resource(fz_context *ctx, xps_document *doc, xps_part *part
{
unsigned char buf[33];
unsigned char key[16];
+ unsigned char *data;
+ size_t size;
char *p;
int i;
- if (part->size < 32)
+ size = fz_buffer_storage(ctx, part->data, &data);
+ if (size < 32)
{
fz_warn(ctx, "insufficient data for font deobfuscation");
return;
@@ -129,8 +132,8 @@ xps_deobfuscate_font_resource(fz_context *ctx, xps_document *doc, xps_part *part
for (i = 0; i < 16; i++)
{
- part->data[i] ^= key[15-i];
- part->data[i+16] ^= key[15-i];
+ data[i] ^= key[15-i];
+ data[i+16] ^= key[15-i];
}
}
@@ -224,14 +227,10 @@ xps_lookup_font(fz_context *ctx, xps_document *doc, char *base_uri, char *font_u
fz_try(ctx)
{
- buf = fz_new_buffer_from_data(ctx, part->data, part->size);
- /* part->data is now owned by buf */
- part->data = NULL;
- font = fz_new_font_from_buffer(ctx, NULL, buf, subfontid, 1);
+ font = fz_new_font_from_buffer(ctx, NULL, part->data, subfontid, 1);
}
fz_always(ctx)
{
- fz_drop_buffer(ctx, buf);
xps_drop_part(ctx, doc, part);
}
fz_catch(ctx)
diff --git a/source/xps/xps-image.c b/source/xps/xps-image.c
index 83f7ac0d..aa495566 100644
--- a/source/xps/xps-image.c
+++ b/source/xps/xps-image.c
@@ -4,10 +4,7 @@
static fz_image *
xps_load_image(fz_context *ctx, xps_document *doc, xps_part *part)
{
- /* Ownership of data always passes in here */
- unsigned char *data = part->data;
- part->data = NULL;
- return fz_new_image_from_data(ctx, data, part->size);
+ return fz_new_image_from_buffer(ctx, part->data);
}
/* FIXME: area unused! */
diff --git a/source/xps/xps-imp.h b/source/xps/xps-imp.h
index 2ba78a50..5db36c5f 100644
--- a/source/xps/xps-imp.h
+++ b/source/xps/xps-imp.h
@@ -54,8 +54,7 @@ typedef struct xps_part_s xps_part;
struct xps_part_s
{
char *name;
- size_t size;
- unsigned char *data;
+ fz_buffer *data;
};
int xps_has_part(fz_context *ctx, xps_document *doc, char *partname);
diff --git a/source/xps/xps-outline.c b/source/xps/xps-outline.c
index bcb16509..472af0c3 100644
--- a/source/xps/xps-outline.c
+++ b/source/xps/xps-outline.c
@@ -86,7 +86,7 @@ xps_load_document_structure(fz_context *ctx, xps_document *doc, xps_fixdoc *fixd
part = xps_read_part(ctx, doc, fixdoc->outline);
fz_try(ctx)
{
- root = fz_parse_xml(ctx, part->data, part->size, 0);
+ root = fz_parse_xml(ctx, part->data, 0);
}
fz_always(ctx)
{
diff --git a/source/xps/xps-resource.c b/source/xps/xps-resource.c
index c0212e3f..139d5b5c 100644
--- a/source/xps/xps-resource.c
+++ b/source/xps/xps-resource.c
@@ -67,7 +67,7 @@ xps_parse_remote_resource_dictionary(fz_context *ctx, xps_document *doc, char *b
part = xps_read_part(ctx, doc, part_name);
fz_try(ctx)
{
- xml = fz_parse_xml(ctx, part->data, part->size, 0);
+ xml = fz_parse_xml(ctx, part->data, 0);
}
fz_always(ctx)
{
diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c
index fe1dcce8..fe363b34 100644
--- a/source/xps/xps-zip.c
+++ b/source/xps/xps-zip.c
@@ -3,8 +3,8 @@
static void xps_init_document(fz_context *ctx, xps_document *doc);
-xps_part *
-xps_new_part(fz_context *ctx, xps_document *doc, char *name, unsigned char *data, size_t size)
+static xps_part *
+xps_new_part(fz_context *ctx, xps_document *doc, char *name, fz_buffer *data)
{
xps_part *part;
@@ -12,13 +12,11 @@ xps_new_part(fz_context *ctx, xps_document *doc, char *name, unsigned char *data
fz_try(ctx)
{
part->name = fz_strdup(ctx, name);
- part->data = data;
- part->size = size;
+ part->data = data; /* take ownership of buffer */
}
fz_catch(ctx)
{
- fz_free(ctx, part->name);
- fz_free(ctx, part->data);
+ fz_drop_buffer(ctx, data);
fz_free(ctx, part);
fz_rethrow(ctx);
}
@@ -30,7 +28,7 @@ void
xps_drop_part(fz_context *ctx, xps_document *doc, xps_part *part)
{
fz_free(ctx, part->name);
- fz_free(ctx, part->data);
+ fz_drop_buffer(ctx, part->data);
fz_free(ctx, part);
}
@@ -43,8 +41,6 @@ xps_read_part(fz_context *ctx, xps_document *doc, char *partname)
fz_archive *zip = doc->zip;
fz_buffer *buf, *tmp;
char path[2048];
- unsigned char *data;
- size_t size;
int count;
char *name;
int seen_last;
@@ -92,11 +88,7 @@ xps_read_part(fz_context *ctx, xps_document *doc, char *partname)
}
}
- fz_terminate_buffer(ctx, buf); /* zero-terminate */
- size = fz_buffer_extract(ctx, buf, &data); /* take over the data ('size' excludes the zero terminator) */
- fz_drop_buffer(ctx, buf);
-
- return xps_new_part(ctx, doc, partname, data, size);
+ return xps_new_part(ctx, doc, partname, buf);
}
int