Skip to content

Commit

Permalink
fix: infinite loop fragmenting large NVM objects with 8 bytes remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Apr 15, 2024
1 parent 0c2e03e commit 831a988
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/nvmedit/src/nvm3/nvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FLASH_MAX_PAGE_SIZE_700,
FLASH_MAX_PAGE_SIZE_800,
NVM3_COUNTER_SIZE,
NVM3_OBJ_HEADER_SIZE_LARGE,
NVM3_OBJ_HEADER_SIZE_SMALL,
NVM3_PAGE_HEADER_SIZE,
NVM3_WORD_SIZE,
Expand Down Expand Up @@ -212,6 +213,13 @@ export function encodeNVM(
|| obj.type === ObjectType.DataLarge
) {
// Large objects may be fragmented

// We need to start a new page, if the remaining space is not enough for
// the object header plus additional data
if (remainingSpace <= NVM3_OBJ_HEADER_SIZE_LARGE) {
nextPage();
}

fragments = fragmentLargeObject(
obj as any,
remainingSpace,
Expand Down

0 comments on commit 831a988

Please sign in to comment.