Skip to content

Commit 39cfa80

Browse files
committed
Added path checks to AssemlyLoading, Binary and SVMLight Loader APIs
1 parent 9216110 commit 39cfa80

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/Microsoft.ML.Core/ComponentModel/AssemblyLoadingUtils.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public static void LoadAndRegister(IHostEnvironment env, string[] assemblies)
3131
{
3232
// REVIEW: Will LoadFrom ever return null?
3333
Contracts.CheckNonEmpty(path, nameof(path));
34+
if (!File.Exists(path))
35+
{
36+
throw Contracts.ExceptParam(nameof(path), "File does not exist at path: {0}", path);
37+
}
3438
var assem = LoadAssembly(env, path);
3539
if (assem != null)
3640
continue;

src/Microsoft.ML.Data/DataLoadSave/Binary/BinaryLoaderSaverCatalog.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public static IDataView LoadFromBinary(this DataOperationsCatalog catalog, IMult
4747
public static IDataView LoadFromBinary(this DataOperationsCatalog catalog, string path)
4848
{
4949
Contracts.CheckNonEmpty(path, nameof(path));
50+
if (!File.Exists(path))
51+
{
52+
throw Contracts.ExceptParam(nameof(path), "File does not exist at path: {0}", path);
53+
}
5054

5155
var env = catalog.GetEnvironment();
5256

src/Microsoft.ML.Transforms/SvmLight/SvmLightLoaderSaverCatalog.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public static IDataView LoadFromSvmLightFile(this DataOperationsCatalog catalog,
6565
bool zeroBased = false)
6666
{
6767
Contracts.CheckNonEmpty(path, nameof(path));
68+
if (!File.Exists(path))
69+
{
70+
throw Contracts.ExceptParam(nameof(path), "File does not exist at path: {0}", path);
71+
}
6872

6973
var file = new MultiFileSource(path);
7074
var loader = catalog.CreateSvmLightLoader(numberOfRows, inputSize, zeroBased, file);
@@ -83,6 +87,10 @@ public static IDataView LoadFromSvmLightFileWithFeatureNames(this DataOperations
8387
long? numberOfRows = null)
8488
{
8589
Contracts.CheckNonEmpty(path, nameof(path));
90+
if (!File.Exists(path))
91+
{
92+
throw Contracts.ExceptParam(nameof(path), "File does not exist at path: {0}", path);
93+
}
8694

8795
var file = new MultiFileSource(path);
8896
var loader = catalog.CreateSvmLightLoaderWithFeatureNames(numberOfRows, file);

0 commit comments

Comments
 (0)