Added better protection against internal leb128 underflow

There have already been a number of bugs that end up writing -1 out as
leb128s. The current encoder doesn't know the different betwee -1 and
0xffffffff, so asserting before this situation can happen is quite
important for preventing these bad leb128s from ever making it into a
stable version.

Also dropped LFS_ERR_OVERFLOW to use LFS_ERR_CORRUPT for bad leb128
encodings. These end up meaning the same thing to higher layers anyways.
This commit is contained in:
Christopher Haster
2023-04-04 12:12:49 -05:00
parent eb93c3b710
commit 355c7466f1
3 changed files with 15 additions and 7 deletions
+2 -2
View File
@@ -30,7 +30,7 @@ ssize_t lfs_toleb128(uint32_t word, void *buffer, size_t size) {
}
}
return LFS_ERR_OVERFLOW;
return LFS_ERR_CORRUPT;
}
ssize_t lfs_fromleb128(uint32_t *word, const void *buffer, size_t size) {
@@ -46,7 +46,7 @@ ssize_t lfs_fromleb128(uint32_t *word, const void *buffer, size_t size) {
}
}
return LFS_ERR_OVERFLOW;
return LFS_ERR_CORRUPT;
}