summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-08-17 15:01:09 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-11-01 13:08:56 +0100
commitf595e889b91a674eb94db7ca4d832da54f5194cd (patch)
tree273b4a7cc465477e428d0c628a19a61301baaae0 /source/pdf
parent2910531c99e80bede06d2f1460459e8f6ce79961 (diff)
downloadmupdf-f595e889b91a674eb94db7ca4d832da54f5194cd.tar.xz
Use int64_t for public file API offsets.
Don't mess with conditional compilation with LARGEFILE -- always expose 64-bit file offsets in our public API.
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-graft.c2
-rw-r--r--source/pdf/pdf-interpret.c2
-rw-r--r--source/pdf/pdf-lex.c2
-rw-r--r--source/pdf/pdf-object.c29
-rw-r--r--source/pdf/pdf-parse.c22
-rw-r--r--source/pdf/pdf-pkcs7.c4
-rw-r--r--source/pdf/pdf-repair.c6
-rw-r--r--source/pdf/pdf-stream.c8
-rw-r--r--source/pdf/pdf-write.c50
-rw-r--r--source/pdf/pdf-xref.c111
10 files changed, 112 insertions, 124 deletions
diff --git a/source/pdf/pdf-graft.c b/source/pdf/pdf-graft.c
index c3d1e116..50454e40 100644
--- a/source/pdf/pdf-graft.c
+++ b/source/pdf/pdf-graft.c
@@ -1,6 +1,8 @@
#include "mupdf/fitz.h"
#include "mupdf/pdf.h"
+#include <assert.h>
+
struct pdf_graft_map_s
{
int refs;
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c
index acebdf87..528f9c90 100644
--- a/source/pdf/pdf-interpret.c
+++ b/source/pdf/pdf-interpret.c
@@ -852,7 +852,7 @@ pdf_process_stream(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, fz_stream
pdf_array_push_drop(ctx, csi->obj, pdf_new_real(ctx, doc, buf->f));
break;
case PDF_TOK_INT:
- pdf_array_push_drop(ctx, csi->obj, pdf_new_int_offset(ctx, doc, buf->i));
+ pdf_array_push_drop(ctx, csi->obj, pdf_new_int(ctx, doc, buf->i));
break;
case PDF_TOK_STRING:
pdf_array_push_drop(ctx, csi->obj, pdf_new_string(ctx, doc, buf->scratch, buf->len));
diff --git a/source/pdf/pdf-lex.c b/source/pdf/pdf-lex.c
index 2a1b4685..44c68557 100644
--- a/source/pdf/pdf-lex.c
+++ b/source/pdf/pdf-lex.c
@@ -645,7 +645,7 @@ void pdf_append_token(fz_context *ctx, fz_buffer *fzbuf, int tok, pdf_lexbuf *bu
fz_append_byte(ctx, fzbuf, '}');
break;
case PDF_TOK_INT:
- fz_append_printf(ctx, fzbuf, "%d", buf->i);
+ fz_append_printf(ctx, fzbuf, "%ld", buf->i);
break;
case PDF_TOK_REAL:
fz_append_printf(ctx, fzbuf, "%g", buf->f);
diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c
index def683d0..7788869e 100644
--- a/source/pdf/pdf-object.c
+++ b/source/pdf/pdf-object.c
@@ -45,7 +45,7 @@ typedef struct pdf_obj_num_s
pdf_obj super;
union
{
- fz_off_t i;
+ int64_t i;
float f;
} u;
} pdf_obj_num;
@@ -111,7 +111,7 @@ 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_new_int(fz_context *ctx, pdf_document *doc, int64_t i)
{
pdf_obj_num *obj;
obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj_num)), "pdf_obj(int)");
@@ -123,18 +123,6 @@ 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 i)
-{
- pdf_obj_num *obj;
- obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj_num)), "pdf_obj(offset)");
- obj->super.refs = 1;
- obj->super.kind = PDF_INT;
- obj->super.flags = 0;
- obj->u.i = i;
- return &obj->super;
-}
-
-pdf_obj *
pdf_new_real(fz_context *ctx, pdf_document *doc, float f)
{
pdf_obj_num *obj;
@@ -315,7 +303,7 @@ int pdf_to_int(fz_context *ctx, pdf_obj *obj)
return 0;
}
-fz_off_t pdf_to_offset(fz_context *ctx, pdf_obj *obj)
+int64_t pdf_to_int64(fz_context *ctx, pdf_obj *obj)
{
RESOLVE(obj);
if (obj < PDF_OBJ__LIMIT)
@@ -323,7 +311,7 @@ fz_off_t pdf_to_offset(fz_context *ctx, pdf_obj *obj)
if (obj->kind == PDF_INT)
return NUM(obj)->u.i;
if (obj->kind == PDF_REAL)
- return (fz_off_t)(NUM(obj)->u.f + 0.5f); /* No roundf in MSVC */
+ return (NUM(obj)->u.f + 0.5f); /* No roundf in MSVC */
return 0;
}
@@ -365,14 +353,7 @@ int pdf_to_str_len(fz_context *ctx, pdf_obj *obj)
return STRING(obj)->len;
}
-void pdf_set_int(fz_context *ctx, pdf_obj *obj, int i)
-{
- if (!OBJ_IS_INT(obj))
- return;
- NUM(obj)->u.i = i;
-}
-
-void pdf_set_int_offset(fz_context *ctx, pdf_obj *obj, fz_off_t i)
+void pdf_set_int(fz_context *ctx, pdf_obj *obj, int64_t i)
{
if (!OBJ_IS_INT(obj))
return;
diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c
index 7772bff2..797d4c56 100644
--- a/source/pdf/pdf-parse.c
+++ b/source/pdf/pdf-parse.c
@@ -322,7 +322,7 @@ pdf_parse_array(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf
{
pdf_obj *ary = NULL;
pdf_obj *obj = NULL;
- fz_off_t a = 0, b = 0, n = 0;
+ int64_t a = 0, b = 0, n = 0;
pdf_token tok;
pdf_obj *op = NULL;
@@ -340,12 +340,12 @@ pdf_parse_array(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf
{
if (n > 0)
{
- obj = pdf_new_int_offset(ctx, doc, a);
+ obj = pdf_new_int(ctx, doc, a);
pdf_array_push_drop(ctx, ary, obj);
}
if (n > 1)
{
- obj = pdf_new_int_offset(ctx, doc, b);
+ obj = pdf_new_int(ctx, doc, b);
pdf_array_push_drop(ctx, ary, obj);
}
n = 0;
@@ -353,7 +353,7 @@ pdf_parse_array(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf
if (tok == PDF_TOK_INT && n == 2)
{
- obj = pdf_new_int_offset(ctx, doc, a);
+ obj = pdf_new_int(ctx, doc, a);
pdf_array_push_drop(ctx, ary, obj);
a = b;
n --;
@@ -438,7 +438,7 @@ pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf *
pdf_obj *key = NULL;
pdf_obj *val = NULL;
pdf_token tok;
- fz_off_t a, b;
+ int64_t a, b;
dict = pdf_new_dict(ctx, doc, 8);
@@ -489,7 +489,7 @@ pdf_parse_dict(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbuf *
if (tok == PDF_TOK_CLOSE_DICT || tok == PDF_TOK_NAME ||
(tok == PDF_TOK_KEYWORD && !strcmp(buf->scratch, "ID")))
{
- val = pdf_new_int_offset(ctx, doc, a);
+ val = pdf_new_int(ctx, doc, a);
pdf_dict_put(ctx, dict, key, val);
pdf_drop_obj(ctx, val);
val = NULL;
@@ -549,7 +549,7 @@ pdf_parse_stm_obj(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbu
case PDF_TOK_TRUE: return pdf_new_bool(ctx, doc, 1); break;
case PDF_TOK_FALSE: return pdf_new_bool(ctx, doc, 0); break;
case PDF_TOK_NULL: return pdf_new_null(ctx, doc); break;
- case PDF_TOK_INT: return pdf_new_int_offset(ctx, doc, buf->i); break;
+ case PDF_TOK_INT: return pdf_new_int(ctx, doc, buf->i); break;
default: fz_throw(ctx, FZ_ERROR_SYNTAX, "unknown token in object stream");
}
}
@@ -557,13 +557,13 @@ pdf_parse_stm_obj(fz_context *ctx, pdf_document *doc, fz_stream *file, pdf_lexbu
pdf_obj *
pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
fz_stream *file, pdf_lexbuf *buf,
- int *onum, int *ogen, fz_off_t *ostmofs, int *try_repair)
+ int *onum, int *ogen, int64_t *ostmofs, int *try_repair)
{
pdf_obj *obj = NULL;
int num = 0, gen = 0;
- fz_off_t stm_ofs;
+ int64_t stm_ofs;
pdf_token tok;
- fz_off_t a, b;
+ int64_t a, b;
int read_next_token = 1;
fz_var(obj);
@@ -619,7 +619,7 @@ pdf_parse_ind_obj(fz_context *ctx, pdf_document *doc,
if (tok == PDF_TOK_STREAM || tok == PDF_TOK_ENDOBJ)
{
- obj = pdf_new_int_offset(ctx, doc, a);
+ obj = pdf_new_int(ctx, doc, a);
read_next_token = 0;
break;
}
diff --git a/source/pdf/pdf-pkcs7.c b/source/pdf/pdf-pkcs7.c
index 26db7909..735548d0 100644
--- a/source/pdf/pdf-pkcs7.c
+++ b/source/pdf/pdf-pkcs7.c
@@ -689,11 +689,11 @@ void pdf_write_digest(fz_context *ctx, pdf_document *doc, const char *filename,
if (p7_len*2 + 2 > digest_length)
fz_throw(ctx, FZ_ERROR_GENERIC, "Insufficient space for digest");
- f = fz_fopen(filename, "rb+");
+ f = fopen(filename, "rb+");
if (f == NULL)
fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to write digest");
- fz_fseek(f, digest_offset+1, SEEK_SET);
+ fseek(f, digest_offset+1, SEEK_SET);
for (i = 0; i < p7_len; i++)
fprintf(f, "%02x", p7_ptr[i]);
diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c
index e4606c27..ca149bd3 100644
--- a/source/pdf/pdf-repair.c
+++ b/source/pdf/pdf-repair.c
@@ -32,7 +32,7 @@ static void add_root(fz_context *ctx, pdf_obj *obj, pdf_obj ***roots, int *num_r
}
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 **root)
+pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, int64_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, int64_t *tmpofs, pdf_obj **root)
{
fz_stream *file = doc->file;
pdf_token tok;
@@ -308,7 +308,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
int num = 0;
int gen = 0;
- fz_off_t tmpofs, stm_ofs, numofs = 0, genofs = 0;
+ int64_t tmpofs, stm_ofs, numofs = 0, genofs = 0;
int stm_len;
pdf_token tok;
int next;
@@ -358,7 +358,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
{
if (memcmp(&buf->scratch[j], "%PDF", 4) == 0)
{
- fz_seek(ctx, doc->file, (fz_off_t)(j + 8), 0); /* skip "%PDF-X.Y" */
+ fz_seek(ctx, doc->file, (int64_t)(j + 8), 0); /* skip "%PDF-X.Y" */
break;
}
}
diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c
index c7bf5285..c89da5c4 100644
--- a/source/pdf/pdf-stream.c
+++ b/source/pdf/pdf-stream.c
@@ -280,7 +280,7 @@ build_filter_chain(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj
* orig_num and orig_gen are used purely to seed the encryption.
*/
static fz_stream *
-pdf_open_raw_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *stmobj, int num, int *orig_num, int *orig_gen, fz_off_t offset)
+pdf_open_raw_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *stmobj, int num, int *orig_num, int *orig_gen, int64_t offset)
{
pdf_xref_entry *x = NULL;
fz_stream *chain2;
@@ -336,7 +336,7 @@ pdf_open_raw_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_ob
* to stream length and decrypting.
*/
static fz_stream *
-pdf_open_filter(fz_context *ctx, pdf_document *doc, fz_stream *chain, pdf_obj *stmobj, int num, fz_off_t offset, fz_compression_params *imparams)
+pdf_open_filter(fz_context *ctx, pdf_document *doc, fz_stream *chain, pdf_obj *stmobj, int num, int64_t offset, fz_compression_params *imparams)
{
pdf_obj *filters;
pdf_obj *params;
@@ -382,7 +382,7 @@ pdf_open_inline_stream(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj, int
{
pdf_obj *filters;
pdf_obj *params;
- fz_off_t offset;
+ int64_t offset;
filters = pdf_dict_geta(ctx, stmobj, PDF_NAME_Filter, PDF_NAME_F);
params = pdf_dict_geta(ctx, stmobj, PDF_NAME_DecodeParms, PDF_NAME_DP);
@@ -479,7 +479,7 @@ pdf_open_stream_number(fz_context *ctx, pdf_document *doc, int num)
}
fz_stream *
-pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, pdf_obj *dict, fz_off_t stm_ofs)
+pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, pdf_obj *dict, int64_t stm_ofs)
{
if (stm_ofs == 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "object is not a stream");
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 164df6b4..9f123206 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -67,7 +67,7 @@ struct pdf_write_state_s
int do_clean;
int *use_list;
- fz_off_t *ofs_list;
+ int64_t *ofs_list;
int *gen_list;
int *renumber_map;
int continue_on_error;
@@ -75,10 +75,10 @@ struct pdf_write_state_s
/* The following extras are required for linearization */
int *rev_renumber_map;
int start;
- fz_off_t first_xref_offset;
- fz_off_t main_xref_offset;
- fz_off_t first_xref_entry_offset;
- fz_off_t file_len;
+ int64_t first_xref_offset;
+ int64_t main_xref_offset;
+ int64_t first_xref_entry_offset;
+ int64_t file_len;
int hints_shared_offset;
int hintstream_len;
pdf_obj *linear_l;
@@ -1460,13 +1460,13 @@ linearize(fz_context *ctx, pdf_document *doc, pdf_write_state *opts)
static void
update_linearization_params(fz_context *ctx, pdf_document *doc, pdf_write_state *opts)
{
- fz_off_t offset;
+ int64_t offset;
pdf_set_int(ctx, opts->linear_l, opts->file_len);
/* Primary hint stream offset (of object, not stream!) */
- pdf_set_int_offset(ctx, opts->linear_h0, opts->ofs_list[pdf_xref_len(ctx, doc)-1]);
+ pdf_set_int(ctx, opts->linear_h0, opts->ofs_list[pdf_xref_len(ctx, doc)-1]);
/* Primary hint stream length (of object, not stream!) */
offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
- pdf_set_int_offset(ctx, opts->linear_h1, offset - opts->ofs_list[pdf_xref_len(ctx, doc)-1]);
+ pdf_set_int(ctx, opts->linear_h1, offset - opts->ofs_list[pdf_xref_len(ctx, doc)-1]);
/* Object number of first pages page object (the first object of page 0) */
pdf_set_int(ctx, opts->linear_o, opts->page_object_lists->page[0]->object[0]);
/* Offset of end of first page (first page is followed by primary
@@ -1474,13 +1474,13 @@ update_linearization_params(fz_context *ctx, pdf_document *doc, pdf_write_state
* primary hint stream counts as part of the first pages data, I think.
*/
offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
- pdf_set_int_offset(ctx, opts->linear_e, offset);
+ pdf_set_int(ctx, opts->linear_e, offset);
/* Number of pages in document */
pdf_set_int(ctx, opts->linear_n, opts->page_count);
/* Offset of first entry in main xref table */
- pdf_set_int_offset(ctx, opts->linear_t, opts->first_xref_entry_offset + opts->hintstream_len);
+ pdf_set_int(ctx, opts->linear_t, opts->first_xref_entry_offset + opts->hintstream_len);
/* Offset of shared objects hint table in the primary hint stream */
- pdf_set_int_offset(ctx, opts->hints_s, opts->hints_shared_offset);
+ pdf_set_int(ctx, opts->hints_s, opts->hints_shared_offset);
/* Primary hint stream length */
pdf_set_int(ctx, opts->hints_length, opts->hintstream_len);
}
@@ -1918,13 +1918,13 @@ static void writexrefsubsect(fz_context *ctx, pdf_write_state *opts, int from, i
for (num = from; num < to; num++)
{
if (opts->use_list[num])
- fz_write_printf(ctx, opts->out, "%010Zd %05d n \n", opts->ofs_list[num], opts->gen_list[num]);
+ fz_write_printf(ctx, opts->out, "%010ld %05d n \n", opts->ofs_list[num], opts->gen_list[num]);
else
- fz_write_printf(ctx, opts->out, "%010Zd %05d f \n", opts->ofs_list[num], opts->gen_list[num]);
+ fz_write_printf(ctx, opts->out, "%010ld %05d f \n", opts->ofs_list[num], opts->gen_list[num]);
}
}
-static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int main_xref_offset, int startxref)
+static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int64_t main_xref_offset, int64_t startxref)
{
pdf_obj *trailer = NULL;
pdf_obj *obj;
@@ -2003,7 +2003,7 @@ static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts,
pdf_drop_obj(ctx, trailer);
- fz_write_printf(ctx, opts->out, "startxref\n%d\n%%%%EOF\n", startxref);
+ fz_write_printf(ctx, opts->out, "startxref\n%ld\n%%%%EOF\n", startxref);
doc->has_xref_streams = 0;
}
@@ -2025,7 +2025,7 @@ static void writexrefstreamsubsect(fz_context *ctx, pdf_document *doc, pdf_write
}
}
-static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int main_xref_offset, int startxref)
+static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int from, int to, int first, int64_t main_xref_offset, int64_t startxref)
{
int num;
pdf_obj *dict = NULL;
@@ -2127,7 +2127,7 @@ static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state
pdf_update_stream(ctx, doc, dict, fzbuf, 0);
writeobject(ctx, doc, opts, num, 0, 0);
- fz_write_printf(ctx, opts->out, "startxref\n%Zd\n%%%%EOF\n", startxref);
+ fz_write_printf(ctx, opts->out, "startxref\n%ld\n%%%%EOF\n", startxref);
}
fz_always(ctx)
{
@@ -2142,9 +2142,9 @@ static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state
}
static void
-padto(fz_context *ctx, fz_output *out, fz_off_t target)
+padto(fz_context *ctx, fz_output *out, int64_t target)
{
- fz_off_t pos = fz_tell_output(ctx, out);
+ int64_t pos = fz_tell_output(ctx, out);
assert(pos <= target);
while (pos < target)
@@ -2218,7 +2218,7 @@ writeobjects(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, int pass
dowriteobject(ctx, doc, opts, num, pass);
if (opts->do_linear && pass == 1)
{
- fz_off_t offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
+ int64_t offset = (opts->start == 1 ? opts->main_xref_offset : opts->ofs_list[1] + opts->hintstream_len);
padto(ctx, opts->out, offset);
}
for (num = 1; num < opts->start; num++)
@@ -2479,7 +2479,7 @@ make_page_offset_hints(fz_context *ctx, pdf_document *doc, pdf_write_state *opts
for (j = 0; j < pop[0]->len; j++)
{
int o = pop[0]->object[j];
- fz_off_t min, max;
+ int64_t min, max;
min = opts->ofs_list[o];
if (o == opts->start-1)
max = opts->main_xref_offset;
@@ -2601,7 +2601,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_st
{
pdf_obj *byte_range;
- f = fz_fopen(filename, "rb+");
+ f = fopen(filename, "rb+");
if (!f)
fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to open %s to complete signatures", filename);
@@ -2610,7 +2610,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_st
{
char *bstr, *cstr, *fstr;
int pnum = pdf_obj_parent_num(ctx, pdf_dict_getl(ctx, usig->field, PDF_NAME_V, PDF_NAME_ByteRange, NULL));
- fz_fseek(f, opts->ofs_list[pnum], SEEK_SET);
+ fseek(f, opts->ofs_list[pnum], SEEK_SET);
(void)fread(buf, 1, sizeof(buf), f);
buf[sizeof(buf)-1] = 0;
@@ -2653,7 +2653,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_st
/* Write the byte range to the file */
for (usig = xref->unsaved_sigs; usig; usig = usig->next)
{
- fz_fseek(f, usig->byte_range_start, SEEK_SET);
+ fseek(f, usig->byte_range_start, SEEK_SET);
fwrite(buf, 1, usig->byte_range_end - usig->byte_range_start, f);
}
@@ -2720,7 +2720,7 @@ static void initialise_write_state(fz_context *ctx, pdf_document *doc, const pdf
* 1 to n access rather than 0..n-1, and add space for 2 new
* extra entries that may be required for linearization. */
opts->use_list = fz_malloc_array(ctx, xref_len + 3, sizeof(int));
- opts->ofs_list = fz_malloc_array(ctx, xref_len + 3, sizeof(fz_off_t));
+ opts->ofs_list = fz_malloc_array(ctx, xref_len + 3, sizeof(int64_t));
opts->gen_list = fz_calloc(ctx, xref_len + 3, sizeof(int));
opts->renumber_map = fz_malloc_array(ctx, xref_len + 3, sizeof(int));
opts->rev_renumber_map = fz_malloc_array(ctx, xref_len + 3, sizeof(int));
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index 92ccf34e..ba2d575f 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -6,6 +6,12 @@
#include <limits.h>
#include <string.h>
+#ifdef _MSC_VER
+#ifndef INT64_MAX
+#define INT64_MAX 9223372036854775807i64
+#endif
+#endif
+
#undef DEBUG_PROGESSIVE_ADVANCE
#ifdef DEBUG_PROGESSIVE_ADVANCE
@@ -588,7 +594,7 @@ pdf_load_version(fz_context *ctx, pdf_document *doc)
{
char buf[20];
- fz_seek(ctx, doc->file, 0, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, 0, SEEK_SET);
fz_read_line(ctx, doc->file, buf, sizeof buf);
if (memcmp(buf, "%PDF-", 5) != 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize version marker");
@@ -604,14 +610,14 @@ pdf_read_start_xref(fz_context *ctx, pdf_document *doc)
{
unsigned char buf[1024];
size_t i, n;
- fz_off_t t;
+ int64_t t;
- fz_seek(ctx, doc->file, 0, FZ_SEEK_END);
+ fz_seek(ctx, doc->file, 0, SEEK_END);
doc->file_size = fz_tell(ctx, doc->file);
- t = fz_maxo(0, doc->file_size - (fz_off_t)sizeof buf);
- fz_seek(ctx, doc->file, t, FZ_SEEK_SET);
+ t = fz_maxi64(0, doc->file_size - (int64_t)sizeof buf);
+ fz_seek(ctx, doc->file, t, SEEK_SET);
n = fz_read(ctx, doc->file, buf, sizeof buf);
if (n < 9)
@@ -628,7 +634,7 @@ pdf_read_start_xref(fz_context *ctx, pdf_document *doc)
doc->startxref = 0;
while (i < n && buf[i] >= '0' && buf[i] <= '9')
{
- if (doc->startxref >= FZ_OFF_MAX/10)
+ if (doc->startxref >= INT64_MAX/10)
fz_throw(ctx, FZ_ERROR_GENERIC, "startxref too large");
doc->startxref = doc->startxref * 10 + (buf[i++] - '0');
}
@@ -673,13 +679,13 @@ static int fz_skip_string(fz_context *ctx, fz_stream *stm, const char *str)
static int
pdf_xref_size_from_old_trailer(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
{
- fz_off_t len;
+ int64_t len;
char *s;
- fz_off_t t;
+ int64_t t;
pdf_token tok;
int c;
int size = 0;
- fz_off_t ofs;
+ int64_t ofs;
pdf_obj *trailer = NULL;
size_t n;
@@ -704,13 +710,13 @@ pdf_xref_size_from_old_trailer(fz_context *ctx, pdf_document *doc, pdf_lexbuf *b
fz_strsep(&s, " "); /* ignore ofs */
if (!s)
fz_throw(ctx, FZ_ERROR_GENERIC, "invalid range marker in xref");
- len = fz_atoo(fz_strsep(&s, " "));
+ len = fz_atoi64(fz_strsep(&s, " "));
if (len < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "xref range marker must be positive");
/* broken pdfs where the section is not on a separate line */
if (s && *s != '\0')
- fz_seek(ctx, doc->file, -(2 + (int)strlen(s)), FZ_SEEK_CUR);
+ fz_seek(ctx, doc->file, -(2 + (int)strlen(s)), SEEK_CUR);
t = fz_tell(ctx, doc->file);
if (t < 0)
@@ -729,10 +735,10 @@ pdf_xref_size_from_old_trailer(fz_context *ctx, pdf_document *doc, pdf_lexbuf *b
else
n = 20;
- if (len > (fz_off_t)((FZ_OFF_MAX - t) / n))
+ if (len > (int64_t)((INT64_MAX - t) / n))
fz_throw(ctx, FZ_ERROR_GENERIC, "xref has too many entries");
- fz_seek(ctx, doc->file, (fz_off_t)(t + n * len), FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, (int64_t)(t + n * len), SEEK_SET);
}
fz_try(ctx)
@@ -760,13 +766,13 @@ pdf_xref_size_from_old_trailer(fz_context *ctx, pdf_document *doc, pdf_lexbuf *b
fz_rethrow(ctx);
}
- fz_seek(ctx, doc->file, ofs, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, ofs, SEEK_SET);
return size;
}
static pdf_xref_entry *
-pdf_xref_find_subsection(fz_context *ctx, pdf_document *doc, fz_off_t ofs, int len)
+pdf_xref_find_subsection(fz_context *ctx, pdf_document *doc, int64_t ofs, int len)
{
pdf_xref *xref = &doc->xref_sections[doc->num_xref_sections-1];
pdf_xref_subsec *sub;
@@ -828,12 +834,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
{
fz_stream *file = doc->file;
- fz_off_t ofs;
+ int64_t ofs;
int len;
char *s;
size_t n;
pdf_token tok;
- fz_off_t i;
+ int64_t i;
int c;
int xref_len = pdf_xref_size_from_old_trailer(ctx, doc, buf);
pdf_xref_entry *table;
@@ -852,19 +858,19 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
fz_read_line(ctx, file, buf->scratch, buf->size);
s = buf->scratch;
- ofs = fz_atoo(fz_strsep(&s, " "));
+ ofs = fz_atoi64(fz_strsep(&s, " "));
len = fz_atoi(fz_strsep(&s, " "));
/* broken pdfs where the section is not on a separate line */
if (s && *s != '\0')
{
fz_warn(ctx, "broken xref section. proceeding anyway.");
- fz_seek(ctx, file, -(2 + (int)strlen(s)), FZ_SEEK_CUR);
+ fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR);
}
if (ofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs);
- if (ofs > FZ_OFF_MAX - len)
+ if (ofs > INT64_MAX - len)
fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big");
/* broken pdfs where size in trailer undershoots entries in xref sections */
@@ -894,7 +900,7 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
while (*s != '\0' && iswhite(*s))
s++;
- entry->ofs = fz_atoo(s);
+ entry->ofs = fz_atoi64(s);
entry->gen = fz_atoi(s + 11);
entry->num = (int)i;
entry->type = s[17];
@@ -922,7 +928,7 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
}
static void
-pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, fz_off_t i0, int i1, int w0, int w1, int w2)
+pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, int64_t i0, int i1, int w0, int w1, int w2)
{
pdf_xref_entry *table;
int i, n;
@@ -937,7 +943,7 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, fz
{
pdf_xref_entry *entry = &table[i-i0];
int a = 0;
- fz_off_t b = 0;
+ int64_t b = 0;
int c = 0;
if (fz_is_eof(ctx, stm))
@@ -972,7 +978,7 @@ pdf_read_new_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
pdf_obj *index = NULL;
pdf_obj *obj = NULL;
int gen, num = 0;
- fz_off_t ofs, stm_ofs;
+ int64_t ofs, stm_ofs;
int size, w0, w1, w2;
int t;
@@ -1059,12 +1065,12 @@ pdf_read_new_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
}
static pdf_obj *
-pdf_read_xref(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *buf)
+pdf_read_xref(fz_context *ctx, pdf_document *doc, int64_t ofs, pdf_lexbuf *buf)
{
pdf_obj *trailer;
int c;
- fz_seek(ctx, doc->file, ofs, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, ofs, SEEK_SET);
while (iswhite(fz_peek_byte(ctx, doc->file)))
fz_read_byte(ctx, doc->file);
@@ -1086,15 +1092,15 @@ struct ofs_list_s
{
int max;
int len;
- fz_off_t *list;
+ int64_t *list;
};
-static fz_off_t
-read_xref_section(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *buf, ofs_list *offsets)
+static int64_t
+read_xref_section(fz_context *ctx, pdf_document *doc, int64_t ofs, pdf_lexbuf *buf, ofs_list *offsets)
{
pdf_obj *trailer = NULL;
- fz_off_t xrefstmofs = 0;
- fz_off_t prevofs = 0;
+ int64_t xrefstmofs = 0;
+ int64_t prevofs = 0;
fz_var(trailer);
@@ -1125,7 +1131,7 @@ read_xref_section(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *
/* FIXME: do we overwrite free entries properly? */
/* FIXME: Does this work properly with progression? */
- xrefstmofs = pdf_to_offset(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_XRefStm));
+ xrefstmofs = pdf_to_int64(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_XRefStm));
if (xrefstmofs)
{
if (xrefstmofs < 0)
@@ -1139,8 +1145,7 @@ read_xref_section(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *
pdf_drop_obj(ctx, pdf_read_xref(ctx, doc, xrefstmofs, buf));
}
- /* FIXME: pdf_to_offset? */
- prevofs = pdf_to_offset(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_Prev));
+ prevofs = pdf_to_int64(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_Prev));
if (prevofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream offset for previous xref stream");
}
@@ -1157,7 +1162,7 @@ read_xref_section(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *
}
static void
-pdf_read_xref_sections(fz_context *ctx, pdf_document *doc, fz_off_t ofs, pdf_lexbuf *buf, int read_previous)
+pdf_read_xref_sections(fz_context *ctx, pdf_document *doc, int64_t ofs, pdf_lexbuf *buf, int read_previous)
{
ofs_list list;
@@ -1263,7 +1268,7 @@ pdf_load_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf)
/* Read this into a local variable here, because pdf_get_xref_entry
* may solidify the xref, hence invalidating "entry", meaning we
* need a stashed value for the throw. */
- fz_off_t ofs = entry->ofs;
+ int64_t ofs = entry->ofs;
if (ofs <= 0 || ofs >= xref_len || pdf_get_xref_entry(ctx, doc, ofs)->type != 'n')
fz_throw(ctx, FZ_ERROR_GENERIC, "invalid reference to an objstm that does not exist: %d (%d 0 R)", (int)ofs, i);
}
@@ -1277,7 +1282,7 @@ pdf_load_linear(fz_context *ctx, pdf_document *doc)
pdf_obj *hint = NULL;
pdf_obj *o;
int num, gen, lin, len;
- fz_off_t stmofs;
+ int64_t stmofs;
fz_var(dict);
fz_var(hint);
@@ -1573,10 +1578,10 @@ pdf_load_obj_stm(fz_context *ctx, pdf_document *doc, int num, pdf_lexbuf *buf, i
fz_stream *stm = NULL;
pdf_obj *objstm = NULL;
int *numbuf = NULL;
- fz_off_t *ofsbuf = NULL;
+ int64_t *ofsbuf = NULL;
pdf_obj *obj;
- fz_off_t first;
+ int64_t first;
int count;
int i;
pdf_token tok;
@@ -1616,13 +1621,13 @@ pdf_load_obj_stm(fz_context *ctx, pdf_document *doc, int num, pdf_lexbuf *buf, i
ofsbuf[i] = buf->i;
}
- fz_seek(ctx, stm, first, FZ_SEEK_SET);
+ fz_seek(ctx, stm, first, SEEK_SET);
for (i = 0; i < count; i++)
{
int xref_len = pdf_xref_len(ctx, doc);
pdf_xref_entry *entry;
- fz_seek(ctx, stm, first + ofsbuf[i], FZ_SEEK_SET);
+ fz_seek(ctx, stm, first + ofsbuf[i], SEEK_SET);
obj = pdf_parse_stm_obj(ctx, doc, stm, buf);
@@ -1683,16 +1688,16 @@ pdf_load_obj_stm(fz_context *ctx, pdf_document *doc, int num, pdf_lexbuf *buf, i
* object loading
*/
static int
-pdf_obj_read(fz_context *ctx, pdf_document *doc, fz_off_t *offset, int *nump, pdf_obj **page)
+pdf_obj_read(fz_context *ctx, pdf_document *doc, int64_t *offset, int *nump, pdf_obj **page)
{
pdf_lexbuf *buf = &doc->lexbuf.base;
int num, gen, tok;
- fz_off_t numofs, genofs, stmofs, tmpofs, newtmpofs;
+ int64_t numofs, genofs, stmofs, tmpofs, newtmpofs;
int xref_len;
pdf_xref_entry *entry;
numofs = *offset;
- fz_seek(ctx, doc->file, numofs, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, numofs, SEEK_SET);
/* We expect to read 'num' here */
tok = pdf_lex(ctx, doc->file, buf);
@@ -1847,7 +1852,7 @@ read_hinted_object(fz_context *ctx, pdf_document *doc, int num)
* there. */
int expected = num;
int curr_pos;
- fz_off_t start, offset;
+ int64_t start, offset;
while (doc->hint_obj_offsets[expected] == 0 && expected > 0)
expected--;
@@ -1898,7 +1903,7 @@ read_hinted_object(fz_context *ctx, pdf_document *doc, int num)
}
fz_always(ctx)
{
- fz_seek(ctx, doc->file, curr_pos, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, curr_pos, SEEK_SET);
}
fz_catch(ctx)
{
@@ -1937,7 +1942,7 @@ object_updated:
}
else if (x->type == 'n')
{
- fz_seek(ctx, doc->file, x->ofs, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, x->ofs, SEEK_SET);
fz_try(ctx)
{
@@ -2398,7 +2403,7 @@ pdf_load_hints(fz_context *ctx, pdf_document *doc, int objnum)
}
/* Skip items 5,6,7 as we don't use them */
- fz_seek(ctx, stream, shared_hint_offset, FZ_SEEK_SET);
+ fz_seek(ctx, stream, shared_hint_offset, SEEK_SET);
/* Read the shared object hints table: Header first */
shared_obj_num = fz_read_bits(ctx, stream, 32);
@@ -2511,16 +2516,16 @@ static void
pdf_load_hint_object(fz_context *ctx, pdf_document *doc)
{
pdf_lexbuf *buf = &doc->lexbuf.base;
- fz_off_t curr_pos;
+ int64_t curr_pos;
curr_pos = fz_tell(ctx, doc->file);
- fz_seek(ctx, doc->file, doc->hint_object_offset, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, doc->hint_object_offset, SEEK_SET);
fz_try(ctx)
{
while (1)
{
pdf_obj *page = NULL;
- fz_off_t tmpofs;
+ int64_t tmpofs;
int num, tok;
tok = pdf_lex(ctx, doc->file, buf);
@@ -2540,7 +2545,7 @@ pdf_load_hint_object(fz_context *ctx, pdf_document *doc)
}
fz_always(ctx)
{
- fz_seek(ctx, doc->file, curr_pos, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, curr_pos, SEEK_SET);
}
fz_catch(ctx)
{
@@ -2601,7 +2606,7 @@ pdf_obj *pdf_progressive_advance(fz_context *ctx, pdf_document *doc, int pagenum
}
fz_always(ctx)
{
- fz_seek(ctx, doc->file, curr_pos, FZ_SEEK_SET);
+ fz_seek(ctx, doc->file, curr_pos, SEEK_SET);
}
fz_catch(ctx)
{