Skip to content

Commit 047bbc7

Browse files
Add error message for empty string in filedataloader.
Differential Revision: D72981574 Pull Request resolved: #10145
1 parent 09c0ce9 commit 047bbc7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

extension/data_loader/file_data_loader.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ Result<FileDataLoader> FileDataLoader::from(
8686
"Alignment %zu is not a power of 2",
8787
alignment);
8888

89+
ET_CHECK_OR_RETURN_ERROR(
90+
file_name != nullptr, InvalidArgument, "File name cannot be empty.");
91+
8992
// Use open() instead of fopen() to avoid the layer of buffering that
9093
// fopen() does. We will be reading large portions of the file in one shot,
9194
// so buffering does not help.

extension/data_loader/test/file_data_loader_test.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ TEST_P(FileDataLoaderTest, FromMissingFileFails) {
154154
EXPECT_NE(fdl.error(), Error::Ok);
155155
}
156156

157+
TEST_P(FileDataLoaderTest, FromEmptyFilePathFails) {
158+
// Nullptr should fail
159+
Result<FileDataLoader> fdl = FileDataLoader::from(nullptr);
160+
EXPECT_NE(fdl.error(), Error::Ok);
161+
}
162+
157163
TEST_P(FileDataLoaderTest, BadAlignmentFails) {
158164
// Create a temp file; contents don't matter.
159165
uint8_t data[256] = {};

0 commit comments

Comments
 (0)