Skip to content

Commit 7735f3a

Browse files
authored
Prevent infinity loop if cloud client falsely report file as directory (#179)
* Prevent inf loop if dir has empty name content * Move check into GetDirectoryContents
1 parent c269d67 commit 7735f3a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/filesystem.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,13 @@ GCSFileSystem::GetDirectoryContents(
721721
// Let set take care of subdirectory contents
722722
std::string item = name.substr(item_start, item_end - item_start);
723723
contents->insert(item);
724+
725+
// Fail-safe check to ensure the item name is not empty
726+
if (item.empty()) {
727+
return Status(
728+
Status::Code::INTERNAL,
729+
"Cannot handle item with empty name at " + path);
730+
}
724731
}
725732
return Status::Success;
726733
}
@@ -1135,6 +1142,12 @@ ASFileSystem::GetDirectoryContents(
11351142
auto func = [&](const as::list_blobs_segmented_item& item,
11361143
const std::string& dir) {
11371144
contents->insert(dir);
1145+
// Fail-safe check to ensure the item name is not empty
1146+
if (dir.empty()) {
1147+
return Status(
1148+
Status::Code::INTERNAL,
1149+
"Cannot handle item with empty name at " + path);
1150+
}
11381151
return Status::Success;
11391152
};
11401153
std::string container, dir_path;
@@ -1777,6 +1790,13 @@ S3FileSystem::GetDirectoryContents(
17771790
// Let set take care of subdirectory contents
17781791
std::string item = name.substr(item_start, item_end - item_start);
17791792
contents->insert(item);
1793+
1794+
// Fail-safe check to ensure the item name is not empty
1795+
if (item.empty()) {
1796+
return Status(
1797+
Status::Code::INTERNAL,
1798+
"Cannot handle item with empty name at " + true_path);
1799+
}
17801800
}
17811801
} else {
17821802
return Status(

0 commit comments

Comments
 (0)