From 6e99c29cf844c6bb57efef530328f63decd4db24 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Tue, 30 Dec 2014 14:18:51 +0100 Subject: [PATCH] Implement guards for stringToBytes and bytesToString --- src/shared/util.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/shared/util.js b/src/shared/util.js index 767f727ea..780af3388 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -439,6 +439,8 @@ var XRefParseException = (function XRefParseExceptionClosure() { function bytesToString(bytes) { + assert(bytes !== null && typeof bytes === 'object' && + bytes.length !== undefined, 'Invalid argument for bytesToString'); var length = bytes.length; var MAX_ARGUMENT_COUNT = 8192; if (length < MAX_ARGUMENT_COUNT) { @@ -454,6 +456,7 @@ function bytesToString(bytes) { } function stringToBytes(str) { + assert(typeof str === 'string', 'Invalid argument for stringToBytes'); var length = str.length; var bytes = new Uint8Array(length); for (var i = 0; i < length; ++i) {