summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-05-14 17:12:42 +0100
committerRobin Watts <robin.watts@artifex.com>2015-05-15 13:06:56 +0100
commit7d5ff30c37c9e5b271fdb2b8cb3219068048322e (patch)
tree5f60d1d03235f2cff161207e00515c5a4a69ef73 /include
parent250e8a11e1debfbd9c4fc84ad895bf923aac135e (diff)
downloadmupdf-7d5ff30c37c9e5b271fdb2b8cb3219068048322e.tar.xz
Support pdf files larger than 2Gig.
If FZ_LARGEFILE is defined when building, MuPDF uses 64bit offsets for files; this allows us to open streams larger than 2Gig. The downsides to this are that: * The xref entries are larger. * All PDF ints are held as 64bit things rather than 32bit things (to cope with /Prev entries, hint stream offsets etc). * All file positions are stored as 64bits rather than 32. The implementation works by detecting FZ_LARGEFILE. Some #ifdeffery in fitz/system.h sets fz_off_t to either int or int64_t as appropriate, and sets defines for fz_fopen, fz_fseek, fz_ftell etc as required. These call the fseeko64 etc functions on linux (and so define _LARGEFILE64_SOURCE) and the explicit 64bit functions on windows.
Diffstat (limited to 'include')
-rw-r--r--include/mupdf/fitz/filter.h2
-rw-r--r--include/mupdf/fitz/math.h7
-rw-r--r--include/mupdf/fitz/stream.h8
-rw-r--r--include/mupdf/fitz/system.h34
-rw-r--r--include/mupdf/pdf/document.h18
-rw-r--r--include/mupdf/pdf/object.h2
-rw-r--r--include/mupdf/pdf/parse.h2
-rw-r--r--include/mupdf/pdf/xref.h10
-rw-r--r--include/mupdf/xps.h2
9 files changed, 63 insertions, 22 deletions
diff --git a/include/mupdf/fitz/filter.h b/include/mupdf/fitz/filter.h
index f200d8c1..07bea7b4 100644
--- a/include/mupdf/fitz/filter.h
+++ b/include/mupdf/fitz/filter.h
@@ -10,7 +10,7 @@
typedef struct fz_jbig2_globals_s fz_jbig2_globals;
fz_stream *fz_open_copy(fz_context *ctx, fz_stream *chain);
-fz_stream *fz_open_null(fz_context *ctx, fz_stream *chain, int len, int offset);
+fz_stream *fz_open_null(fz_context *ctx, fz_stream *chain, int len, fz_off_t offset);
fz_stream *fz_open_concat(fz_context *ctx, int max, int pad);
void fz_concat_push(fz_context *ctx, fz_stream *concat, fz_stream *chain); /* Ownership of chain is passed in */
fz_stream *fz_open_arc4(fz_context *ctx, fz_stream *chain, unsigned char *key, unsigned keylen);
diff --git a/include/mupdf/fitz/math.h b/include/mupdf/fitz/math.h
index 54c8f0c8..9e413b7c 100644
--- a/include/mupdf/fitz/math.h
+++ b/include/mupdf/fitz/math.h
@@ -33,6 +33,8 @@ float fz_atof(const char *s);
/* atoi that copes with NULL */
int fz_atoi(const char *s);
+fz_off_t fz_atoo(const char *s);
+
/*
Some standard math functions, done as static inlines for speed.
People with compilers that do not adequately implement inlines may
@@ -68,6 +70,11 @@ static inline int fz_maxi(int a, int b)
return (a > b ? a : b);
}
+static inline fz_off_t fz_maxo(fz_off_t a, fz_off_t b)
+{
+ return (a > b ? a : b);
+}
+
static inline float fz_clamp(float f, float min, float max)
{
return (f > min ? (f < max ? f : max) : min);
diff --git a/include/mupdf/fitz/stream.h b/include/mupdf/fitz/stream.h
index 003e1bbe..b07e7ce3 100644
--- a/include/mupdf/fitz/stream.h
+++ b/include/mupdf/fitz/stream.h
@@ -104,7 +104,7 @@ void fz_drop_stream(fz_context *ctx, fz_stream *stm);
/*
fz_tell: return the current reading position within a stream
*/
-int fz_tell(fz_context *ctx, fz_stream *stm);
+fz_off_t fz_tell(fz_context *ctx, fz_stream *stm);
/*
fz_seek: Seek within a stream.
@@ -115,7 +115,7 @@ int fz_tell(fz_context *ctx, fz_stream *stm);
whence: From where the offset is measured (see fseek).
*/
-void fz_seek(fz_context *ctx, fz_stream *stm, int offset, int whence);
+void fz_seek(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence);
/*
fz_read: Read from a stream into a given data block.
@@ -157,7 +157,7 @@ int fz_stream_meta(fz_context *ctx, fz_stream *stm, int key, int size, void *ptr
typedef int (fz_stream_next_fn)(fz_context *ctx, fz_stream *stm, int max);
typedef void (fz_stream_close_fn)(fz_context *ctx, void *state);
-typedef void (fz_stream_seek_fn)(fz_context *ctx, fz_stream *stm, int offset, int whence);
+typedef void (fz_stream_seek_fn)(fz_context *ctx, fz_stream *stm, fz_off_t offset, int whence);
typedef int (fz_stream_meta_fn)(fz_context *ctx, fz_stream *stm, int key, int size, void *ptr);
struct fz_stream_s
@@ -165,7 +165,7 @@ struct fz_stream_s
int refs;
int error;
int eof;
- int pos;
+ fz_off_t pos;
int avail;
int bits;
unsigned char *rp, *wp;
diff --git a/include/mupdf/fitz/system.h b/include/mupdf/fitz/system.h
index 1ae66eea..0088bd64 100644
--- a/include/mupdf/fitz/system.h
+++ b/include/mupdf/fitz/system.h
@@ -1,6 +1,15 @@
#ifndef MUPDF_FITZ_SYSTEM_H
#define MUPDF_FITZ_SYSTEM_H
+/* The very first decision we need to make is, are we using the 64bit
+ * file pointers code. This must happen before the stdio.h include. */
+#ifdef FZ_LARGEFILE
+/* Set _LARGEFILE64_SOURCE so that we know fopen64 et al will be declared. */
+#ifndef _LARGEFILE64_SOURCE
+#define _LARGEFILE64_SOURCE
+#endif
+#endif
+
/*
Include the standard libc headers.
*/
@@ -100,7 +109,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz);
FILE *fz_fopen_utf8(const char *name, const char *mode);
-#define fopen fz_fopen_utf8
+#define fz_fopen fz_fopen_utf8
char *fz_utf8_from_wchar(const wchar_t *s);
wchar_t *fz_wchar_from_utf8(const char *s);
@@ -109,6 +118,10 @@ FILE *fz_fopen_utf8(const char *name, const char *mode);
char **fz_argv_from_wargv(int argc, wchar_t **wargv);
void fz_free_argv(int argc, char **argv);
+#define fseeko64 _fseeki64
+#define ftello64 _ftelli64
+#define atoll _atoi64
+
#else /* Unix or close enough */
#include <stdint.h>
@@ -122,6 +135,25 @@ void fz_free_argv(int argc, char **argv);
#endif
+#ifdef FZ_LARGEFILE
+#ifndef fz_fopen
+#define fz_fopen fopen64
+#endif
+typedef int64_t fz_off_t;
+#define fz_fseek fseeko64
+#define fz_ftell ftello64
+#define fz_atoo_imp atoll
+#else
+#ifndef fz_fopen
+#define fz_fopen fopen
+#endif
+#define fz_fseek fseek
+#define fz_ftell ftell
+typedef int fz_off_t;
+#define fz_atoo_imp atoi
+#endif
+
+
#ifdef __ANDROID__
#include <android/log.h>
#define LOG_TAG "libmupdf"
diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h
index 41ee6b07..8f2c6ef6 100644
--- a/include/mupdf/pdf/document.h
+++ b/include/mupdf/pdf/document.h
@@ -24,7 +24,7 @@ struct pdf_lexbuf_s
int size;
int base_size;
int len;
- int i;
+ fz_off_t i;
float f;
char *scratch;
char buffer[PDF_LEXBUF_SMALL];
@@ -170,8 +170,8 @@ struct pdf_document_s
fz_stream *file;
int version;
- int startxref;
- int file_size;
+ fz_off_t startxref;
+ fz_off_t file_size;
pdf_crypt *crypt;
pdf_ocg_descriptor *ocg;
pdf_hotspot hotspot;
@@ -190,14 +190,14 @@ struct pdf_document_s
/* State indicating which file parsing method we are using */
int file_reading_linearly;
- int file_length;
+ fz_off_t file_length;
pdf_obj *linear_obj; /* Linearized object (if used) */
pdf_obj **linear_page_refs; /* Page objects for linear loading */
int linear_page1_obj_num;
/* The state for the pdf_progressive_advance parser */
- int linear_pos;
+ fz_off_t linear_pos;
int linear_page_num;
int hint_object_offset;
@@ -221,17 +221,17 @@ struct pdf_document_s
struct
{
int number; /* Page object number */
- int offset; /* Offset of page object */
- int index; /* Index into shared hint_shared_ref */
+ fz_off_t offset; /* Offset of page object */
+ fz_off_t index; /* Index into shared hint_shared_ref */
} *hint_page;
int *hint_shared_ref;
struct
{
int number; /* Object number of first object */
- int offset; /* Offset of first object */
+ fz_off_t offset; /* Offset of first object */
} *hint_shared;
int hint_obj_offsets_max;
- int *hint_obj_offsets;
+ fz_off_t *hint_obj_offsets;
int resources_localised;
diff --git a/include/mupdf/pdf/object.h b/include/mupdf/pdf/object.h
index 2db0e57b..433419a3 100644
--- a/include/mupdf/pdf/object.h
+++ b/include/mupdf/pdf/object.h
@@ -14,6 +14,7 @@ typedef struct pdf_obj_s pdf_obj;
pdf_obj *pdf_new_null(fz_context *ctx, pdf_document *doc);
pdf_obj *pdf_new_bool(fz_context *ctx, pdf_document *doc, int b);
pdf_obj *pdf_new_int(fz_context *ctx, pdf_document *doc, int i);
+pdf_obj *pdf_new_int_offset(fz_context *ctx, pdf_document *doc, fz_off_t off);
pdf_obj *pdf_new_real(fz_context *ctx, pdf_document *doc, float f);
pdf_obj *pdf_new_name(fz_context *ctx, pdf_document *doc, const char *str);
pdf_obj *pdf_new_string(fz_context *ctx, pdf_document *doc, const char *str, int len);
@@ -74,6 +75,7 @@ void pdf_clean_obj(fz_context *ctx, pdf_obj *obj);
/* safe, silent failure, no error reporting on type mismatches */
int pdf_to_bool(fz_context *ctx, pdf_obj *obj);
int pdf_to_int(fz_context *ctx, pdf_obj *obj);
+fz_off_t pdf_to_offset(fz_context *ctx, pdf_obj *obj);
float pdf_to_real(fz_context *ctx, pdf_obj *obj);
char *pdf_to_name(fz_context *ctx, pdf_obj *obj);
char *pdf_to_str_buf(fz_context *ctx, pdf_obj *obj);
diff --git a/include/mupdf/pdf/parse.h b/include/mupdf/pdf/parse.h
index 23584029..ea715326 100644
--- a/include/mupdf/pdf/parse.h
+++ b/include/mupdf/pdf/parse.h
@@ -29,7 +29,7 @@ pdf_token pdf_lex_no_string(fz_context *ctx, fz_stream *f, pdf_lexbuf *lexbuf);
pdf_obj *pdf_parse_array(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_stm_obj(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
-pdf_obj *pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf, int *num, int *gen, int *stm_ofs, int *try_repair);
+pdf_obj *pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc, fz_stream *f, pdf_lexbuf *buf, int *num, int *gen, fz_off_t *stm_ofs, int *try_repair);
/*
pdf_print_token: print a lexed token to a buffer, growing if necessary
diff --git a/include/mupdf/pdf/xref.h b/include/mupdf/pdf/xref.h
index aa54605f..845c936e 100644
--- a/include/mupdf/pdf/xref.h
+++ b/include/mupdf/pdf/xref.h
@@ -36,8 +36,8 @@ struct pdf_xref_entry_s
char type; /* 0=unset (f)ree i(n)use (o)bjstm */
unsigned char flags; /* bit 0 = marked */
unsigned short gen; /* generation / objstm index */
- int ofs; /* file offset / objstm object number */
- int stm_ofs; /* on-disk stream */
+ fz_off_t ofs; /* file offset / objstm object number */
+ fz_off_t stm_ofs; /* on-disk stream */
fz_buffer *stm_buf; /* in-memory stream (for updated objects) */
pdf_obj *obj; /* stored/cached object */
};
@@ -53,7 +53,7 @@ struct pdf_xref_subsec_s
{
pdf_xref_subsec *next;
int len;
- int start;
+ fz_off_t start;
pdf_xref_entry *table;
};
@@ -79,7 +79,7 @@ fz_stream *pdf_open_stream(fz_context *ctx, pdf_document *doc, int num, int gen)
fz_stream *pdf_open_inline_stream(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, fz_compression_params *params);
fz_compressed_buffer *pdf_load_compressed_stream(fz_context *ctx, pdf_document *doc, int num, int gen);
void pdf_load_compressed_inline_image(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int length, fz_stream *cstm, int indexed, fz_image *image);
-fz_stream *pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, int gen, pdf_obj *dict, int stm_ofs);
+fz_stream *pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, int gen, pdf_obj *dict, fz_off_t stm_ofs);
fz_stream *pdf_open_compressed_stream(fz_context *ctx, fz_compressed_buffer *);
fz_stream *pdf_open_contents_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj);
fz_buffer *pdf_load_raw_renumbered_stream(fz_context *ctx, pdf_document *doc, int num, int gen, int orig_num, int orig_gen);
@@ -103,7 +103,7 @@ void pdf_mark_xref(fz_context *ctx, pdf_document *doc);
void pdf_clear_xref(fz_context *ctx, pdf_document *doc);
void pdf_clear_xref_to_mark(fz_context *ctx, pdf_document *doc);
-int pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, int *tmpofs);
+int pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, fz_off_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, fz_off_t *tmpofs);
pdf_obj *pdf_progressive_advance(fz_context *ctx, pdf_document *doc, int pagenum);
diff --git a/include/mupdf/xps.h b/include/mupdf/xps.h
index 13c8eea0..fd21fe7c 100644
--- a/include/mupdf/xps.h
+++ b/include/mupdf/xps.h
@@ -216,7 +216,7 @@ typedef struct xps_entry_s xps_entry;
struct xps_entry_s
{
char *name;
- int offset;
+ fz_off_t offset;
int csize;
int usize;
};