Skip to content

Commit

Permalink
update mupdf
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Oct 28, 2023
1 parent 2cb96f2 commit e94e6c8
Show file tree
Hide file tree
Showing 34 changed files with 1,421 additions and 115 deletions.
5 changes: 5 additions & 0 deletions mupdf/CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
List of changes in MuPDF 1.24

Removed deprecated functions:
pdf_check_signature

List of changes in MuPDF 1.23.0

New features:
Expand Down
7 changes: 6 additions & 1 deletion mupdf/include/mupdf/fitz/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ int fz_caught(fz_context *ctx);
This assumes no intervening use of fz_try/fz_catch.
*/
void fz_rethrow_if(fz_context *ctx, int errcode);
void fz_rethrow_unless(fz_context *ctx, int errcode);

/**
Format an error message, and log it to the registered
Expand Down Expand Up @@ -174,19 +175,23 @@ void fz_end_throw_on_repair(fz_context *ctx);
#define fz_vwarn(CTX, FMT, VA) fz_vwarnFL(CTX, __FILE__, __LINE__, FMT, VA)
#define fz_warn(CTX, ...) fz_warnFL(CTX, __FILE__, __LINE__, __VA_ARGS__)
#define fz_rethrow_if(CTX, ERRCODE) fz_rethrow_ifFL(CTX, __FILE__, __LINE__, ERRCODE)
#define fz_rethrow_unless(CTX, ERRCODE) fz_rethrow_unlessFL(CTX, __FILE__, __LINE__, ERRCODE)
#define fz_log_error_printf(CTX, ...) fz_log_error_printfFL(CTX, __FILE__, __LINE__, __VA_ARGS__)
#define fz_vlog_error_printf(CTX, FMT, VA) fz_log_error_printfFL(CTX, __FILE__, __LINE__, FMT, VA)
#define fz_log_error(CTX, STR) fz_log_error_printfFL(CTX, __FILE__, __LINE__, STR)
#define fz_do_catch(CTX) fz_do_catchFL(CTX, __FILE__, __LINE__)
FZ_NORETURN void fz_vthrowFL(fz_context *ctx, const char *file, int line, int errcode, const char *fmt, va_list ap);
FZ_NORETURN void fz_throwFL(fz_context *ctx, const char *file, int line, int errcode, const char *fmt, ...) FZ_PRINTFLIKE(5,6);
FZ_NORETURN void fz_rethrowFL(fz_context *ctx, const char *file, int line);
void fz_morph_errorFL(fz_context *ctx, const char *file, int line, int fromcode, int tocode);
void fz_vwarnFL(fz_context *ctx, const char *file, int line, const char *fmt, va_list ap);
void fz_warnFL(fz_context *ctx, const char *file, int line, const char *fmt, ...) FZ_PRINTFLIKE(4,5);
void fz_rethrow_ifFL(fz_context *ctx, const char *file, int line, int errcode);
void fz_rethrow_unlessFL(fz_context *ctx, const char *file, int line, int errcode);
void fz_log_error_printfFL(fz_context *ctx, const char *file, int line, const char *fmt, ...) FZ_PRINTFLIKE(4,5);
void fz_vlog_error_printfFL(fz_context *ctx, const char *file, int line, const char *fmt, va_list ap);
void fz_log_errorFL(fz_context *ctx, const char *file, int line, const char *str);
int fz_do_catchFL(fz_context *ctx, const char *file, int line);
#endif

enum
Expand Down Expand Up @@ -699,7 +704,7 @@ void fz_var_imp(void *);
fz_jmp_buf *fz_push_try(fz_context *ctx);
int fz_do_try(fz_context *ctx);
int fz_do_always(fz_context *ctx);
int fz_do_catch(fz_context *ctx);
int (fz_do_catch)(fz_context *ctx);

#ifndef FZ_JMPBUF_ALIGN
#define FZ_JMPBUF_ALIGN 32
Expand Down
8 changes: 0 additions & 8 deletions mupdf/include/mupdf/pdf/form.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,6 @@ fz_pixmap *pdf_preview_signature_as_pixmap(fz_context *ctx,
const char *reason,
const char *location);

/*
check a signature's certificate chain and digest
This is a helper function defined to provide compatibility with older
versions of mupdf
*/
int pdf_check_signature(fz_context *ctx, pdf_pkcs7_verifier *verifier, pdf_document *doc, pdf_obj *signature, char *ebuf, size_t ebufsize);

void pdf_drop_signer(fz_context *ctx, pdf_pkcs7_signer *signer);
void pdf_drop_verifier(fz_context *ctx, pdf_pkcs7_verifier *verifier);

Expand Down
3 changes: 3 additions & 0 deletions mupdf/platform/java/mupdf_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static JavaVM *jvm = NULL;

/* All the cached classes/mids/fids we need. */

static jclass cls_AbortException;
static jclass cls_AlertResult;
static jclass cls_Archive;
static jclass cls_ArrayOfQuad;
Expand Down Expand Up @@ -1249,6 +1250,7 @@ static int find_fids(JNIEnv *env)
mid_TreeArchive_init = get_method(&err, env, "<init>", "(J)V");
fid_TreeArchive_pointer = get_field(&err, env, "pointer", "J");

cls_AbortException = get_class(&err, env, PKG"AbortException");
cls_TryLaterException = get_class(&err, env, PKG"TryLaterException");

/* Standard Java classes */
Expand Down Expand Up @@ -1306,6 +1308,7 @@ static void jni_detach_thread(jboolean detach)

static void lose_fids(JNIEnv *env)
{
(*env)->DeleteGlobalRef(env, cls_AbortException);
(*env)->DeleteGlobalRef(env, cls_AlertResult);
(*env)->DeleteGlobalRef(env, cls_Archive);
(*env)->DeleteGlobalRef(env, cls_ArrayOfQuad);
Expand Down
30 changes: 30 additions & 0 deletions mupdf/platform/java/src/com/artifex/mupdf/fitz/AbortException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2004-2023 Artifex Software, Inc.
//
// This file is part of MuPDF.
//
// MuPDF is free software: you can redistribute it and/or modify it under the
// terms of the GNU Affero General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
// details.
//
// You should have received a copy of the GNU Affero General Public License
// along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
//
// Alternative licensing terms are available from the licensor.
// For commercial licensing, see <https://www.artifex.com/> or contact
// Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
// CA 94129, USA, for further information.

package com.artifex.mupdf.fitz;

public class AbortException extends RuntimeException
{
AbortException(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions mupdf/platform/wasm/lib/mupdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class TryLaterError extends Error {
}
}

class AbortError extends Error {
constructor(message) {
super(message)
this.name = "AbortError"
}
}

const libmupdf_injections = {
fetchOpen,
fetchRead,
Expand Down
1 change: 1 addition & 0 deletions mupdf/platform/win32/javaviewerlib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="..\java\src\com\artifex\mupdf\fitz\AbortException.java" />
<None Include="..\java\src\com\artifex\mupdf\fitz\Annotation.java" />
<None Include="..\java\src\com\artifex\mupdf\fitz\Buffer.java" />
<None Include="..\java\src\com\artifex\mupdf\fitz\BufferInputStream.java" />
Expand Down
3 changes: 3 additions & 0 deletions mupdf/platform/win32/javaviewerlib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="..\java\src\com\artifex\mupdf\fitz\AbortException.java">
<Filter>com/artifex/mupdf/fitz</Filter>
</None>
<None Include="..\java\src\com\artifex\mupdf\fitz\Annotation.java">
<Filter>com/artifex/mupdf/fitz</Filter>
</None>
Expand Down
1 change: 1 addition & 0 deletions mupdf/platform/win32/libmupdf.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@
<ClCompile Include="..\..\source\html\html-outline.c" />
<ClCompile Include="..\..\source\html\html-parse.c" />
<ClCompile Include="..\..\source\html\mobi.c" />
<ClCompile Include="..\..\source\html\office.c" />
<ClCompile Include="..\..\source\html\story-writer.c" />
<ClCompile Include="..\..\source\html\xml-dom.c" />
<ClCompile Include="..\..\source\pdf\pdf-annot.c" />
Expand Down
3 changes: 3 additions & 0 deletions mupdf/platform/win32/libmupdf.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@
<ClCompile Include="..\..\source\html\story-writer.c">
<Filter>html</Filter>
</ClCompile>
<ClCompile Include="..\..\source\html\office.c">
<Filter>html</Filter>
</ClCompile>
<ClCompile Include="..\..\source\fitz\encode-fax.c">
<Filter>fitz</Filter>
</ClCompile>
Expand Down
3 changes: 1 addition & 2 deletions mupdf/platform/x11/pdfapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,7 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai
mediabox = fz_bound_page(app->ctx, app->page);
fz_catch(app->ctx)
{
if (fz_caught(app->ctx) != FZ_ERROR_TRYLATER)
fz_rethrow(app->ctx);
fz_rethrow_unless(app->ctx, FZ_ERROR_TRYLATER);
mediabox = fz_make_rect(0, 0, 100, 100);
app->incomplete = 1;
}
Expand Down
8 changes: 6 additions & 2 deletions mupdf/source/fitz/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ fz_try_read_archive_entry(fz_context *ctx, fz_archive *arch, const char *name)
char *local_name;
fz_buffer *buf = NULL;

if (arch == NULL || !arch->read_entry)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read archive entry");
if (arch == NULL || !arch->read_entry || !arch->has_entry || name == NULL)
return NULL;

local_name = fz_cleanname(fz_strdup(ctx, name));

fz_var(buf);

fz_try(ctx)
{
if (!arch->has_entry(ctx, arch, local_name))
break;
buf = arch->read_entry(ctx, arch, local_name);
}
fz_always(ctx)
fz_free(ctx, local_name);
fz_catch(ctx)
Expand Down
2 changes: 1 addition & 1 deletion mupdf/source/fitz/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ fz_new_bitmap(fz_context *ctx, int w, int h, int n, int xres, int yres)
/* Stride is 32 bit aligned. We may want to make this 64 bit if we use SSE2 etc. */
int stride = ((n * w + 31) & ~31) >> 3;
if (h < 0 || ((size_t)h > (size_t)(SIZE_MAX / stride)))
fz_throw(ctx, FZ_ERROR_MEMORY, "bitmap too large");
fz_throw(ctx, FZ_ERROR_GENERIC, "bitmap too large");

bit = fz_malloc_struct(ctx, fz_bitmap);
fz_try(ctx)
Expand Down
2 changes: 2 additions & 0 deletions mupdf/source/fitz/document-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern fz_document_handler xhtml_document_handler;
extern fz_document_handler mobi_document_handler;
extern fz_document_handler epub_document_handler;
extern fz_document_handler txt_document_handler;
extern fz_document_handler office_document_handler;

void fz_register_document_handlers(fz_context *ctx)
{
Expand All @@ -57,6 +58,7 @@ void fz_register_document_handlers(fz_context *ctx)
fz_register_document_handler(ctx, &xhtml_document_handler);
fz_register_document_handler(ctx, &mobi_document_handler);
fz_register_document_handler(ctx, &txt_document_handler);
fz_register_document_handler(ctx, &office_document_handler);
#endif /* FZ_ENABLE_HTML */
#if FZ_ENABLE_EPUB
fz_register_document_handler(ctx, &epub_document_handler);
Expand Down
9 changes: 3 additions & 6 deletions mupdf/source/fitz/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,7 @@ fz_run_page_contents(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix t
fz_catch(ctx)
{
dev->close_device = NULL; /* aborted run, don't warn about unclosed device */
if (fz_caught(ctx) != FZ_ERROR_ABORT)
fz_rethrow(ctx);
fz_rethrow_unless(ctx, FZ_ERROR_ABORT);
}
}
}
Expand All @@ -727,8 +726,7 @@ fz_run_page_annots(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix tra
fz_catch(ctx)
{
dev->close_device = NULL; /* aborted run, don't warn about unclosed device */
if (fz_caught(ctx) != FZ_ERROR_ABORT)
fz_rethrow(ctx);
fz_rethrow_unless(ctx, FZ_ERROR_ABORT);
}
}
}
Expand All @@ -745,8 +743,7 @@ fz_run_page_widgets(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix tr
fz_catch(ctx)
{
dev->close_device = NULL; /* aborted run, don't warn about unclosed device */
if (fz_caught(ctx) != FZ_ERROR_ABORT)
fz_rethrow(ctx);
fz_rethrow_unless(ctx, FZ_ERROR_ABORT);
}
}
}
Expand Down
27 changes: 26 additions & 1 deletion mupdf/source/fitz/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ int fz_do_always(fz_context *ctx)
#endif
}

int fz_do_catch(fz_context *ctx)
int (fz_do_catch)(fz_context *ctx)
{
ctx->error.errcode = ctx->error.top->code;
return (ctx->error.top--)->state > 1;
Expand Down Expand Up @@ -369,6 +369,13 @@ void (fz_rethrow_if)(fz_context *ctx, int err)
fz_rethrow(ctx);
}

void (fz_rethrow_unless)(fz_context *ctx, int err)
{
assert(ctx && ctx->error.errcode >= FZ_ERROR_NONE);
if (ctx->error.errcode != err)
fz_rethrow(ctx);
}

#if FZ_VERBOSE_EXCEPTIONS
static const char *
errcode_to_string(int exc)
Expand Down Expand Up @@ -398,6 +405,14 @@ errcode_to_string(int exc)
}
}

int fz_do_catchFL(fz_context *ctx, const char *file, int line)
{
int rc = (fz_do_catch)(ctx);
if (rc)
(fz_log_error_printf)(ctx, "%s:%d: Catching", file, line);
return rc;
}


void fz_log_error_printfFL(fz_context *ctx, const char *file, int line, const char *fmt, ...)
{
Expand Down Expand Up @@ -473,6 +488,16 @@ void fz_morph_errorFL(fz_context *ctx, const char *file, int line, int fromerr,
}
}

void fz_rethrow_unlessFL(fz_context *ctx, const char *file, int line, int err)
{
assert(ctx && ctx->error.errcode >= FZ_ERROR_NONE);
if (ctx->error.errcode != err)
{
(fz_log_error_printf)(ctx, "%s:%d: Rethrowing", file, line);
(fz_rethrow)(ctx);
}
}

void fz_rethrow_ifFL(fz_context *ctx, const char *file, int line, int err)
{
assert(ctx && ctx->error.errcode >= FZ_ERROR_NONE);
Expand Down
2 changes: 1 addition & 1 deletion mupdf/source/fitz/load-png.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ png_deinterlace(fz_context *ctx, struct info *info, unsigned int *passw, unsigne
unsigned int p, x, y, k;

if (info->height > UINT_MAX / stride)
fz_throw(ctx, FZ_ERROR_MEMORY, "image too large");
fz_throw(ctx, FZ_ERROR_GENERIC, "image too large");
output = Memento_label(fz_malloc(ctx, info->height * stride), "png_deinterlace");

for (p = 0; p < 7; p++)
Expand Down
2 changes: 1 addition & 1 deletion mupdf/source/fitz/load-tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ tiff_decode_samples(fz_context *ctx, struct tiff *tiff)
unsigned i;

if (tiff->imagelength > UINT_MAX / tiff->stride)
fz_throw(ctx, FZ_ERROR_MEMORY, "image too large");
fz_throw(ctx, FZ_ERROR_GENERIC, "image too large");
tiff->samples = Memento_label(fz_malloc(ctx, (size_t)tiff->imagelength * tiff->stride), "tiff_samples");
memset(tiff->samples, 0x00, (size_t)tiff->imagelength * tiff->stride);

Expand Down
2 changes: 1 addition & 1 deletion mupdf/source/fitz/pixmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ fz_subsample_pixmap(fz_context *ctx, fz_pixmap *tile, int factor)
tile->stride = tile->w * (size_t)tile->n;
/* Redundant test? We only ever make pixmaps smaller! */
if (tile->h > INT_MAX / (tile->w * tile->n))
fz_throw(ctx, FZ_ERROR_MEMORY, "pixmap too large");
fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap too large");
tile->samples = fz_realloc(ctx, tile->samples, (size_t)tile->h * tile->w * tile->n);
}

Expand Down
Loading

0 comments on commit e94e6c8

Please sign in to comment.