summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-11-25 14:25:49 +0000
committerRobin Watts <Robin.Watts@artifex.com>2016-12-08 11:57:22 +0000
commit907e47b14bbe54732f760962695f853678fc3899 (patch)
treef34faf30a2d11fced42252227d2013b7308f1435
parent4916a2fa24e65fab1e961a5a6702c929287ed39c (diff)
downloadmupdf-907e47b14bbe54732f760962695f853678fc3899.tar.xz
Update pdf_array_put to allow extension.
Previously, attempting to put an object beyond the end of an array would throw an error. Here we update the code to allow objects to be placed *exactly* at the end (i.e. to extend the length by 1). Update js use of pdf_array_put.
-rw-r--r--source/pdf/pdf-object.c7
-rw-r--r--source/tools/murun.c5
2 files changed, 7 insertions, 5 deletions
diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c
index 6f481942..f78fbadd 100644
--- a/source/pdf/pdf-object.c
+++ b/source/pdf/pdf-object.c
@@ -694,7 +694,12 @@ pdf_array_put(fz_context *ctx, pdf_obj *obj, int i, pdf_obj *item)
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
- if (i < 0 || i >= ARRAY(obj)->len)
+ if (i == ARRAY(obj)->len)
+ {
+ pdf_array_push(ctx, obj, item);
+ return;
+ }
+ if (i < 0 || i > ARRAY(obj)->len)
fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds");
if (!item)
diff --git a/source/tools/murun.c b/source/tools/murun.c
index 63266226..5469483a 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -2929,10 +2929,7 @@ static int ffi_pdf_obj_put(js_State *J, void *obj, const char *key)
if (is_number(key, &idx)) {
fz_try(ctx)
- if (idx == pdf_array_len(ctx, obj))
- pdf_array_push(ctx, obj, val);
- else
- pdf_array_put(ctx, obj, idx, val);
+ pdf_array_put(ctx, obj, idx, val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx)