Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34ebc8f4 authored by Donald Chai's avatar Donald Chai
Browse files

[aapt2] Fix infinite loop in proguard::CollectLocations

std::set only works correctly when the < comparator is a strict weak
ordering, while UsageLocation::operator< was actually implementing !=.

Bug: 134190468
Change-Id: Icb9407e9c8451f9fcb4eb9b2cea310e3bcaf159e
Tested: aapt2_tests, and b/134190468#comment1
(cherry picked from commit 44fa342e)
parent c000664c
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -99,11 +99,13 @@ bool CollectLocations(const UsageLocation& location, const KeepSet& keep_set,
//

inline bool operator==(const UsageLocation& lhs, const UsageLocation& rhs) {
  // The "source" member is ignored because we only need "name" for outputting
  // keep rules; "source" is used for comments.
  return lhs.name == rhs.name;
}

inline int operator<(const UsageLocation& lhs, const UsageLocation& rhs) {
  return lhs.name.compare(rhs.name);
inline bool operator<(const UsageLocation& lhs, const UsageLocation& rhs) {
  return lhs.name.compare(rhs.name) < 0;
}

//
+8 −0
Original line number Diff line number Diff line
@@ -364,4 +364,12 @@ TEST(ProguardRulesTest, TransitionRulesAreEmitted) {
    "-keep class com.foo.Bar { <init>(android.content.Context, android.util.AttributeSet); }"));
}

TEST(ProguardRulesTest, UsageLocationComparator) {
  proguard::UsageLocation location1 = {{"pkg", ResourceType::kAttr, "x"}};
  proguard::UsageLocation location2 = {{"pkg", ResourceType::kAttr, "y"}};

  EXPECT_EQ(location1 < location2, true);
  EXPECT_EQ(location2 < location1, false);
}

}  // namespace aapt