scripts: Added -w/--word-bits to bound dbgleb128/dbgle32 parsing

This is limited to dbgle32.py, dbgleb128.py, and dbgtag.py for now.

This more closely matches how littlefs behaves, in that we read a
bounded number of bytes before leb128 decoding. This minimizes bugs
related to leb128 overflow and avoids reading inherently undecodable
data.

The previous unbounded behavior is still available with -w0.

Note this gives dbgle32.py much more flexibility in that it can now
decode other integer widths. Uh, ignore the name for now. At least it's
self documenting that the default is 32-bits...

---

Also fixed a bug in fromleb128 where size was reported incorrectly on
offset + truncated leb128.
This commit is contained in:
Christopher Haster
2025-04-14 16:26:21 -05:00
parent 0cea8b96fb
commit bd70270e11
9 changed files with 91 additions and 28 deletions

View File

@@ -213,7 +213,7 @@ def fromleb128(data, j=0):
if not b & 0x80:
return word, d+1
d += 1
return word, len(data)
return word, d
def fromtag(data, j=0):
d = 0