From 9092198b1b9c65ad4c0bc0aee7a24ecc809b6a9a Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 17 May 2016 09:48:00 -0700 Subject: [PATCH] Terminate startup code with a null byte, too (indexed file random access bundles) Reviewed By: javache Differential Revision: D3310269 fbshipit-source-id: d0fbf5afd6baecf50ec568e8694a15c96e6a9c85 --- local-cli/bundle/output/unbundle/as-indexed-file.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/local-cli/bundle/output/unbundle/as-indexed-file.js b/local-cli/bundle/output/unbundle/as-indexed-file.js index a475f9ab0..45eb412c8 100644 --- a/local-cli/bundle/output/unbundle/as-indexed-file.js +++ b/local-cli/bundle/output/unbundle/as-indexed-file.js @@ -67,13 +67,14 @@ function writeBuffers(stream, buffers) { }); } +function nullTerminatedBuffer(contents, encoding) { + return Buffer.concat([Buffer(contents, encoding), nullByteBuffer]); +} + function moduleToBuffer(id, code, encoding) { return { id, - buffer: Buffer.concat([ - Buffer(code, encoding), - nullByteBuffer // create \0-terminated strings - ]) + buffer: nullTerminatedBuffer(code, encoding), }; } @@ -129,7 +130,7 @@ function buildTableAndContents(startupCode, modules, encoding) { // - code blob char[] null-terminated code strings, starting with // the startup code - const startupCodeBuffer = Buffer(startupCode, encoding); + const startupCodeBuffer = nullTerminatedBuffer(startupCode, encoding); const moduleBuffers = buildModuleBuffers(modules, encoding); const table = buildModuleTable(startupCodeBuffer, moduleBuffers);