Skip to content

Mark LRU buffer invalid if reading fails - #89

Open
MCJack123 wants to merge 1 commit into
FreeRTOS:mainfrom
MCJack123:patch-1
Open

MCJack123 wants to merge 1 commit into
FreeRTOS:mainfrom
MCJack123:patch-1

Conversation

@MCJack123

Copy link
Copy Markdown

Description

This PR fixes an issue with buffer corruption that may occur if a block transfer fails. In FF_GetBuffer, if the underlying block reader in FF_BlockRead partially reads data into the buffer but fails, the function returns a failure state without updating the buffer it attempted reading on. This can cause a future request for the sector previously used for that buffer to return the half-read data for the sector that was being read.

The bug is solved by marking a failed buffer as invalid, and also setting the sector to 0 just to make double sure it doesn't get grabbed again.

Test Steps

  1. Call FF_GetBuffer on enough different sectors to saturate the buffer list.
  2. Call FF_GetBuffer on a new sector to overwrite an old buffer, but trigger a transfer failure in the middle of reading somehow.
  3. Call FF_GetBuffer on the sectors read in step 1 in reverse order until the contents of the buffer do not represent the actual sector contents.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

N/A

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant