From 7afa8a5bd78a99e7750a74c60432a307b7cbd761 Mon Sep 17 00:00:00 2001 From: John McPherson Date: Tue, 11 Aug 2020 12:52:46 -0700 Subject: [PATCH] Handle empty and flat out invalid files better --- src/AppInstallerCommonCore/Public/AppInstallerErrors.h | 1 + src/AppInstallerRepositoryCore/Manifest/YamlParser.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/AppInstallerCommonCore/Public/AppInstallerErrors.h b/src/AppInstallerCommonCore/Public/AppInstallerErrors.h index 8e82b5b06e..a3542da57d 100644 --- a/src/AppInstallerCommonCore/Public/AppInstallerErrors.h +++ b/src/AppInstallerCommonCore/Public/AppInstallerErrors.h @@ -51,6 +51,7 @@ #define APPINSTALLER_CLI_ERROR_LIBYAML_ERROR ((HRESULT)0x8A150027) #define APPINSTALLER_CLI_ERROR_MANIFEST_VALIDATION_WARNING ((HRESULT)0x8A150028) #define APPINSTALLER_CLI_ERROR_MANIFEST_VALIDATION_FAILURE ((HRESULT)0x8A150029) +#define APPINSTALLER_CLI_ERROR_INVALID_MANIFEST ((HRESULT)0x8A15002A) namespace AppInstaller { diff --git a/src/AppInstallerRepositoryCore/Manifest/YamlParser.cpp b/src/AppInstallerRepositoryCore/Manifest/YamlParser.cpp index 9ff40524ba..30b5f806ca 100644 --- a/src/AppInstallerRepositoryCore/Manifest/YamlParser.cpp +++ b/src/AppInstallerRepositoryCore/Manifest/YamlParser.cpp @@ -196,6 +196,12 @@ namespace AppInstaller::Manifest std::vector YamlParser::ParseManifest(const YAML::Node& rootNode, Manifest& manifest, bool fullValidation) { + // Detects empty files with a better error. + if (!rootNode.IsMap()) + { + THROW_EXCEPTION_MSG(ManifestException(APPINSTALLER_CLI_ERROR_INVALID_MANIFEST), "The manifest does not contain a valid root."); + } + // Detect manifest version first to determine expected fields // Use index to access ManifestVersion directly. If there're duplicates or other general errors, it'll be detected in later // processing of iterating the whole manifest.