Skip to content

Reject zero-length Airoha TLV to avoid extraction hang - #1601

Open
bunlongheng wants to merge 1 commit into
onekey-sec:mainfrom
bunlongheng:fix/airoha-tlv-zero-length-loop
Open

Reject zero-length Airoha TLV to avoid extraction hang#1601
bunlongheng wants to merge 1 commit into
onekey-sec:mainfrom
bunlongheng:fix/airoha-tlv-zero-length-loop

Conversation

@bunlongheng

Copy link
Copy Markdown

While reading the Airoha handler I noticed _read_sections can spin forever. It walks the TLV list looking for MOVER_INFO, and each iteration does file.seek(tlv.tlv_length, SEEK_CUR) before parsing the next TLV. If a crafted image has a TLV whose length is 0 and it isn't MOVER_INFO, the seek advances nothing, the same 4 bytes get parsed again, and the loop never terminates, so unblob just hangs on that input with no timeout.

I added a guard that bails out with InvalidInputFormat when a TLV reports zero length, plus a stop once the walk runs off the end of the file before finding MOVER_INFO. Valid images are unaffected since their TLVs advance normally.

@qkaiser qkaiser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch !

Comment on lines +77 to +78
if file.tell() >= file.size():
raise InvalidInputFormat("Airoha MOVER_INFO TLV not found")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dissect.cstruct parsing after this line will raise EOFError when the file is fully consumed. Your conditional on tlv_length is sufficient, you can remove this one.

@qkaiser qkaiser self-assigned this Aug 10, 2026
@qkaiser qkaiser added bug Something isn't working python Pull requests that update Python code format:vendor Custom vendor format labels Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working format:vendor Custom vendor format python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants