summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-10-11 16:36:19 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-10-12 15:18:07 +0200
commitb5c4bee884e9c4a5f988d21cec22abd9ddd0edcf (patch)
treea8cb1e93a0da15915480862031a683aef9dce6f1 /source
parent992c7c6cf15813760f4582682f5a48daba5d4239 (diff)
downloadmupdf-b5c4bee884e9c4a5f988d21cec22abd9ddd0edcf.tar.xz
Fix bug in murun when creating buffers from strings.
The code only worked for string literals, not garbage collected or short strings.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/buffer.c9
-rw-r--r--source/tools/murun.c2
2 files changed, 10 insertions, 1 deletions
diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c
index a43ff296..7068803a 100644
--- a/source/fitz/buffer.c
+++ b/source/fitz/buffer.c
@@ -68,6 +68,15 @@ fz_new_buffer_from_shared_data(fz_context *ctx, const unsigned char *data, size_
}
fz_buffer *
+fz_new_buffer_from_copied_data(fz_context *ctx, const unsigned char *data, size_t size)
+{
+ fz_buffer *b = fz_new_buffer(ctx, size);
+ b->len = size;
+ memcpy(b->data, data, size);
+ return b;
+}
+
+fz_buffer *
fz_new_buffer_from_base64(fz_context *ctx, const char *data, size_t size)
{
fz_buffer *buf = fz_new_buffer(ctx, size);
diff --git a/source/tools/murun.c b/source/tools/murun.c
index dd93b138..5925ba4f 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -763,7 +763,7 @@ static fz_buffer *ffi_tobuffer(js_State *J, int idx)
else {
const char *str = js_tostring(J, idx);
fz_try(ctx)
- buf = fz_new_buffer_from_shared_data(ctx, (const unsigned char *)str, strlen(str));
+ buf = fz_new_buffer_from_copied_data(ctx, (const unsigned char *)str, strlen(str));
fz_catch(ctx)
rethrow(J);
}