From d78b4f3246db406d5b2c786a8cb7b95aaa7803b9 Mon Sep 17 00:00:00 2001 From: rabbitboots Date: Mon, 28 Feb 2022 13:06:52 -0400 Subject: [PATCH 1/3] Add type check to nativefs.getInfo() Checks that argument #1 (path) is of type 'string'. --- nativefs.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nativefs.lua b/nativefs.lua index 053df73..16e7ca9 100644 --- a/nativefs.lua +++ b/nativefs.lua @@ -392,6 +392,9 @@ local function leaf(p) end function nativefs.getInfo(path, filtertype) + if type(path) ~= 'string' then + error("bad argument #1 to 'getInfo' (string expected, got " .. type(path) .. ")") + end local dir = path:match("(.*[\\/]).*$") or './' local file = leaf(path) local result, err = withTempMount(dir, getInfo, file, filtertype) From 975de5de9eb5bd284feeb1be193a98373dfb6a39 Mon Sep 17 00:00:00 2001 From: rabbitboots Date: Mon, 28 Feb 2022 15:56:17 -0400 Subject: [PATCH 2/3] Add type check to nativefs.getDirectoryItems(dir) Most incorrect types for 'dir' are caught deeper into the call stack, but passing nil causes a coredump. This type-check mirrors the behavior of love.filesystem.getDirectoryItems(). --- nativefs.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nativefs.lua b/nativefs.lua index 16e7ca9..1a3739b 100644 --- a/nativefs.lua +++ b/nativefs.lua @@ -351,6 +351,9 @@ local function withTempMount(dir, fn, ...) end function nativefs.getDirectoryItems(dir) + if type(dir) ~= "string" then + error("bad argument #1 to 'getDirectoryItems' (string expected, got " .. type(dir) .. ")") + end local result, err = withTempMount(dir, love.filesystem.getDirectoryItems) return result or {} end From 5ca1313e858d8359aa4381122a1b2b8cffeb5322 Mon Sep 17 00:00:00 2001 From: rabbitboots Date: Mon, 28 Feb 2022 16:25:05 -0400 Subject: [PATCH 3/3] Add type check to nativefs.getDirectoryItemsInfo() Fixes coredump caused by passing nil to argument #1 of nativefs.getDirectoryItemsInfo(). Aside: An invalid arg #2 (filtertype) can slip by if the inner function doesn't iterate over any actual directory items. Perhaps it would be better to type-check in withTempMount(), as that seems to be the source of the issue here and in getDirectoryItems(). --- nativefs.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nativefs.lua b/nativefs.lua index 1a3739b..2214bfc 100644 --- a/nativefs.lua +++ b/nativefs.lua @@ -373,6 +373,9 @@ local function getDirectoryItemsInfo(path, filtertype) end function nativefs.getDirectoryItemsInfo(path, filtertype) + if type(path) ~= "string" then + error("bad argument #1 to 'getDirectoryItemsInfo' (string expected, got " .. type(path) .. ")") + end local result, err = withTempMount(path, getDirectoryItemsInfo, filtertype) return result or {} end