Skip to content

Commit

Permalink
fix: infinite loop fragmenting large NVM objects with 8 bytes remaini…
Browse files Browse the repository at this point in the history
…ng (#6769)
  • Loading branch information
AlCalzone authored Apr 15, 2024
1 parent 0c2e03e commit f819144
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 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,11 @@ 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 f819144

Please sign in to comment.