Skip to content

Commit

Permalink
Check for malformed list when parsing hybrid topology metadata CPU list.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 643155348
  • Loading branch information
gmarin13 authored and shantuo committed Jul 10, 2024
1 parent 607f0b5 commit 5b27c28
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/quipper/string_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool ParseCPUNumbers(const std::string& cpus, std::vector<uint32_t>& result) {
std::vector<std::string> range_tokens;
SplitString(token, '-', &range_tokens);

if (range_tokens.size() > 2) {
if (range_tokens.empty() || range_tokens.size() > 2) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/quipper/string_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ TEST(StringUtilsTest, ParseCPUNumbers) {
EXPECT_THAT(result, ElementsAre(0, 1, 2, 3, 5, 6, 7));
result.clear();
EXPECT_FALSE(ParseCPUNumbers("", result));
EXPECT_FALSE(ParseCPUNumbers(",", result));
EXPECT_FALSE(ParseCPUNumbers("a", result));
EXPECT_FALSE(ParseCPUNumbers("0,1-2-3", result));
}
Expand Down

0 comments on commit 5b27c28

Please sign in to comment.