From 6f6e0c4f48b83a5edb0e1a940cfc696567c209d8 Mon Sep 17 00:00:00 2001 From: Johannes Kalmbach Date: Thu, 23 Jan 2025 18:17:44 +0100 Subject: [PATCH] Fix an out-of-bounds read in the OPTIONAL JOIN implementation (#1710) --- src/util/JoinAlgorithms/JoinAlgorithms.h | 3 +++ test/EngineTest.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/util/JoinAlgorithms/JoinAlgorithms.h b/src/util/JoinAlgorithms/JoinAlgorithms.h index 0b897e1c8e..17288c2599 100644 --- a/src/util/JoinAlgorithms/JoinAlgorithms.h +++ b/src/util/JoinAlgorithms/JoinAlgorithms.h @@ -491,6 +491,9 @@ void specialOptionalJoin( elFromFirstNotFoundAction(it); } it1 = next1; + if (it1 == end1) { + break; + } checkCancellation(); diff --git a/test/EngineTest.cpp b/test/EngineTest.cpp index e6fcc1e76f..860fa5521e 100644 --- a/test/EngineTest.cpp +++ b/test/EngineTest.cpp @@ -278,6 +278,18 @@ TEST(OptionalJoin, specialOptionalJoinTwoColumns) { IdTable expectedResult = makeIdTableFromVector( {{4, 1, 2, U}, {2, 1, 3, 3}, {1, 1, 4, U}, {2, 2, 2, 4}, {1, 3, 1, 1}}); + testOptionalJoin(a, b, jcls, expectedResult); + } + { + // Test a corner case that previously contained a bug. + IdTable a{makeIdTableFromVector({{4, U, 2}})}; + IdTable b{makeIdTableFromVector({{3, 3, 1}})}; + // Join a and b on the column pairs 1,2 and 2,1 (entries from columns 1 of + // a have to equal those of column 2 of b and vice versa). + JoinColumns jcls{{1, 2}, {2, 1}}; + + IdTable expectedResult = makeIdTableFromVector({{4, U, 2, U}}); + testOptionalJoin(a, b, jcls, expectedResult); } }