From db0ead70a4370d7f5b8dfa605c5b85af8068b9fd Mon Sep 17 00:00:00 2001 From: cemonneau <57847267+cemonneau@users.noreply.github.com> Date: Thu, 11 Nov 2021 20:12:06 +0100 Subject: [PATCH] Fix image parsing when the upgrade file identifier is not at position 0 (#59) --- lib/ota.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ota.js b/lib/ota.js index de81648..42741b5 100644 --- a/lib/ota.js +++ b/lib/ota.js @@ -8,7 +8,10 @@ function parseSubElement(buffer, position) { return {tagID, length, data}; } -function parseImage(buffer) { +function parseImage(rawBuffer) { + const start = rawBuffer.indexOf(upgradeFileIdentifier); + const buffer = rawBuffer.slice(start); + const header = { otaUpgradeFileIdentifier: buffer.subarray(0, 4), otaHeaderVersion: buffer.readUInt16LE(4), @@ -55,4 +58,4 @@ function parseImage(buffer) { module.exports = { parseImage -}; \ No newline at end of file +};