Skip to content

Commit

Permalink
Implement guards for stringToBytes and bytesToString
Browse files Browse the repository at this point in the history
  • Loading branch information
timvandermeij authored and speedplane committed Feb 24, 2015
1 parent 14f7461 commit c544601
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit c544601

Please sign in to comment.