Skip to content

Commit

Permalink
test: guard large string decoder allocation
Browse files Browse the repository at this point in the history
Use common.enoughTestMem to avoid "Array buffer allocation failed"
error on low memory devices.

Fixes: nodejs#36792

PR-URL: nodejs#36795
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Pooja D P <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
targos authored and aduh95 committed Jan 5, 2021
1 parent ca86e34 commit e5b8c61
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/parallel/test-string-decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,14 @@ assert.throws(
}
);

assert.throws(
() => new StringDecoder().write(Buffer.alloc(0x1fffffe8 + 1).fill('a')),
{
code: 'ERR_STRING_TOO_LONG',
}
);
if (common.enoughTestMem) {
assert.throws(
() => new StringDecoder().write(Buffer.alloc(0x1fffffe8 + 1).fill('a')),
{
code: 'ERR_STRING_TOO_LONG',
}
);
}

// Test verifies that StringDecoder will correctly decode the given input
// buffer with the given encoding to the expected output. It will attempt all
Expand Down

0 comments on commit e5b8c61

Please sign in to comment.