From 9c88a5c1ab8fb1537418cb5d2c705251d24b56c6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Mar 2016 09:35:35 -0800 Subject: [PATCH] Check ReferencesParent before calling MakeAbsoluteFilePath --- atom/common/api/atom_api_native_image.cc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index b1f0e9c5a6f0..d26fdab8c602 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -120,6 +120,20 @@ bool PopulateImageSkiaRepsFromPath(gfx::ImageSkia* image, return succeed; } +base::FilePath MakePathAbsolute(const base::FilePath& path) { + if (!path.ReferencesParent()) { + return path; + } + + base::FilePath absolute_path = MakeAbsoluteFilePath(path); + // MakeAbsoluteFilePath returns an empty path on failures so use original path + if (absolute_path.empty()) { + return path; + } else { + return absolute_path; + } +} + #if defined(OS_MACOSX) bool IsTemplateFilename(const base::FilePath& path) { return (base::MatchPattern(path.value(), "*Template.*") || @@ -255,12 +269,7 @@ mate::Handle NativeImage::CreateFromJPEG( mate::Handle NativeImage::CreateFromPath( v8::Isolate* isolate, const base::FilePath& path) { gfx::ImageSkia image_skia; - - base::FilePath absolute_path = MakeAbsoluteFilePath(path); - // MakeAbsoluteFilePath returns an empty path on failures so use original path - if (absolute_path.empty()) { - absolute_path = path; - } + base::FilePath absolute_path = MakePathAbsolute(path); if (absolute_path.MatchesExtension(FILE_PATH_LITERAL(".ico"))) { #if defined(OS_WIN)