From c1c1cc81576bf54c80d672b448c8ef11057b3ab2 Mon Sep 17 00:00:00 2001 From: Brad Chamberlain Date: Mon, 13 Apr 2020 16:09:42 -0700 Subject: [PATCH] Merge pull request #15511 from bradcray/fix-sort-tuple-oob-race Fix race-y out-of-bounds tuple indexing error in Sort.chpl [reviewed by @ben-albrecht] This fixes an out-of-bounds error in tuple indexing that only happens occasionally in practice (~1% of the time when compiling with --verify on my Mac for test/library/packages/Sort/correctness/test-radix-bucketizer.chpl) and as a result slipped through testing until now. It's also subtle in that it's done indirectly by a routine that takes the thing to be indexed into (often an array, but this time a tuple) and its bounds as arguments, so there was indirection involved. Searching through the code, I'm not seeing other obvious places that would be running afoul of the same issue. --- modules/packages/Sort.chpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/packages/Sort.chpl b/modules/packages/Sort.chpl index 4b7549994d24..c207d0df71f6 100644 --- a/modules/packages/Sort.chpl +++ b/modules/packages/Sort.chpl @@ -1856,7 +1856,7 @@ module SequentialInPlacePartitioning { while offsets[curbin] < endfast { // Now go through the records in buf // putting them in their right home. - for (idx, bin) in bucketizer.classify(buf, 1, max_buf, + for (idx, bin) in bucketizer.classify(buf, 0, max_buf-1, criterion, startbit) { // Swap buf[j] into its appropriate bin. // Leave buf[j] with the next unsorted item.