diff options
author | 2023-03-31 22:37:42 +0000 | |
---|---|---|
committer | 2023-04-03 22:50:25 +0000 | |
commit | f24b9a438d4246607d14eaa04d405c089cb758db (patch) | |
tree | 97a70da03e609314ff07e2d52096a1b1523dd172 /tools/aapt2/ResourceUtils.cpp | |
parent | 00558ac53ab84e3ddc9e356452a32c8a0b8ab437 (diff) |
Add additional check on float precision after parsing, only compile the
value when precision is not lost.
Bug: b/69347762
Test: Verified affected atests pass
Change-Id: I8e4fcd420a924f0e949bfd3a8aae23d1e7d582b1
Diffstat (limited to 'tools/aapt2/ResourceUtils.cpp')
-rw-r--r-- | tools/aapt2/ResourceUtils.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp index 5a118a902963..e670f3803c30 100644 --- a/tools/aapt2/ResourceUtils.cpp +++ b/tools/aapt2/ResourceUtils.cpp @@ -670,8 +670,19 @@ std::unique_ptr<Item> TryParseItemForAttribute( // Try parsing this as a float. auto floating_point = TryParseFloat(value); if (floating_point) { + // Only check if the parsed result lost precision when the parsed item is + // android::Res_value::TYPE_FLOAT and there is other possible types saved in type_mask, like + // ResTable_map::TYPE_INTEGER. if (type_mask & AndroidTypeToAttributeTypeMask(floating_point->value.dataType)) { - return std::move(floating_point); + const bool mayOnlyBeFloat = (type_mask & ~float_mask) == 0; + const bool parsedAsFloat = floating_point->value.dataType == android::Res_value::TYPE_FLOAT; + if (!mayOnlyBeFloat && parsedAsFloat) { + if (floating_point->toPrettyString() == value.data()) { + return std::move(floating_point); + } + } else { + return std::move(floating_point); + } } } } |