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:
+2
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user