Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reject decoding strings that are passing the string block in size #1044

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion androguard/core/axml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ def _decode8(self, offset:int) -> str:
encoded_bytes, skip = self._decode_length(offset, 1)
offset += skip

# Two checks should happen here:
# a) offset + encoded_bytes surpassing the string_pool length and
# b) non-null terminated strings which should be rejected
# platform/frameworks/base/libs/androidfw/ResourceTypes.cpp#789
if len(self.m_charbuff) < (offset + encoded_bytes):
logger.warning(f"String size: {offset + encoded_bytes} is exceeding string pool size. Returning empty string.")
return ""
data = self.m_charbuff[offset: offset + encoded_bytes]

if self.m_charbuff[offset + encoded_bytes] != 0:
Expand All @@ -264,6 +271,14 @@ def _decode16(self, offset:int) -> str:
# The len is the string len in utf-16 units
encoded_bytes = str_len * 2

# Two checks should happen here:
# a) offset + encoded_bytes surpassing the string_pool length and
# b) non-null terminated strings which should be rejected
# platform/frameworks/base/libs/androidfw/ResourceTypes.cpp#789
if len(self.m_charbuff) < (offset + encoded_bytes):
logger.warning(f"String size: {offset + encoded_bytes} is exceeding string pool size. Returning empty string.")
return ""

data = self.m_charbuff[offset: offset + encoded_bytes]

if self.m_charbuff[offset + encoded_bytes:offset + encoded_bytes + 2] != b"\x00\x00":
Expand Down Expand Up @@ -835,7 +850,7 @@ def getAttributeName(self, index:int):
":")
if res != self.sb[name]:
self.packerwarning = True

if not res or res == ":":
# Attach the HEX Number, so for multiple missing attributes we do not run
# into problems.
Expand Down