Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loss of data a possibility? #555

Open
SaimShuja opened this issue Oct 28, 2022 · 0 comments
Open

loss of data a possibility? #555

SaimShuja opened this issue Oct 28, 2022 · 0 comments

Comments

@SaimShuja
Copy link

following code accumulate record data from hex file into the optibootdata page buffer

`// append record

uint16_t recLen = getHexValue(buf, 2);
for (uint16_t i=0; i<recLen; i++)
  optibootData->pageBuf[optibootData->pageLen++] = getHexValue(buf+8+2*i, 2);
// program page, if we have a full page
if (optibootData->pageLen >= optibootData->pgmSz) {
  //DBG("OB full\n");
  DBG("processRecord %d, call programPage() %08x\n", optibootData->pgmSz, optibootData->address + optibootData->segment);
  if (!programPage()) return false;
} `

reference

it expects that data length in one line of hex file be exactly 8*2 bytes,
but if record length is not exactly 16 bytes for example is 14 bytes or 10 bytes then first record will be accumulated in page buffer , then optibootData->pageLen will be 2 bytes less then 128bytes which is the page size of MCU, thus making it read one more record into page buffer , but when it reads another record which is 16 bytes makeing optibootData->pageLen greater then 128 , rather 126+16 in case of a (14 byte record present). and it will full fill the condition (optibootData->pageLen >= optibootData->pgmSz) thus will program the page into the MCU , but when programing page it will only write first 128 bytes of page buffer as under.

uint16_t pgmLen = optibootData->pageLen; if (pgmLen > optibootData->pgmSz) pgmLen = optibootData->pgmSz;\ DBG("OB pgm %d@0x%x\n", pgmLen, optibootData->address);
reference

which will cause discarding of bytes above 128 in the page buffer thus rendering the programmed firmware faulty, because then the firmware written to the MCU will not have those discarded bytes (bytes 129 - 142) .

this file works this file works because the less bytes record is at the end, so no extra bytes are read into the buffer
this fails this fails because it reads more byte which are later discarded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant