From c8c3cc35fcc41e3180fbe4deeae8d59a990ef157 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 23 Nov 2021 12:41:40 +0000 Subject: [PATCH] Fix crash in rdcarray comparison --- renderdoc/api/replay/rdcarray.h | 2 +- renderdoc/replay/basic_types_tests.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/renderdoc/api/replay/rdcarray.h b/renderdoc/api/replay/rdcarray.h index 3a2057515..11fa9cb8e 100644 --- a/renderdoc/api/replay/rdcarray.h +++ b/renderdoc/api/replay/rdcarray.h @@ -182,7 +182,7 @@ public: c = o.usedCount; // compare the range - int comp = ItemHelper::compRange(elems, o.elems, usedCount); + int comp = ItemHelper::compRange(elems, o.elems, c); // if it's not equal, we can return either true or false now if(comp != 0) return (comp < 0); diff --git a/renderdoc/replay/basic_types_tests.cpp b/renderdoc/replay/basic_types_tests.cpp index d88476b0e..18e37b592 100644 --- a/renderdoc/replay/basic_types_tests.cpp +++ b/renderdoc/replay/basic_types_tests.cpp @@ -250,6 +250,13 @@ TEST_CASE("Test array type", "[basictypes]") CHECK(test2 < test); CHECK_FALSE(test < test2); CHECK_FALSE(test == test2); + + // ensure in the case of comparing different sized arrays we don't read off the end of one + rdcarray emptyTest; + + CHECK(emptyTest < test); + CHECK_FALSE(test < emptyTest); + CHECK_FALSE(test == test2); }; SECTION("Comparison test with non-trivial type") @@ -293,6 +300,13 @@ TEST_CASE("Test array type", "[basictypes]") CHECK(test2 < test); CHECK_FALSE(test < test2); CHECK_FALSE(test == test2); + + // ensure in the case of comparing different sized arrays we don't read off the end of one + rdcarray emptyTest; + + CHECK(emptyTest < test); + CHECK_FALSE(test < emptyTest); + CHECK_FALSE(test == test2); } SECTION("Test constructing/assigning from other types")