summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-07-10 23:33:35 +0800
committerGitHub <[email protected]>2026-07-10 23:33:35 +0800
commit369e46bd1e5bcb88b380965962cf6da0089aec80 (patch)
treea3b7fbab2c62ffecd1ba4b3d2ff639970e7acf8b
parent3a0b131873815ff3c2d4d133885f1e691823e945 (diff)
parent9d654aa671f8aae9df7f1480221aaebe491e4d65 (diff)
Merge pull request #7644 from xmake-io/path
Fix path translate
m---------core/src/tbox/tbox0
-rw-r--r--core/src/xmake/path/translate.c18
-rw-r--r--xmake/modules/private/service/remote_build/filesync.lua5
3 files changed, 20 insertions, 3 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox
-Subproject 38e3a97a38c4551271639a689e77060369b4746
+Subproject 622da925c4c61e15f16d89ab39d840867c42a11
diff --git a/core/src/xmake/path/translate.c b/core/src/xmake/path/translate.c
index 0c2b22a1b..ce2e83169 100644
--- a/core/src/xmake/path/translate.c
+++ b/core/src/xmake/path/translate.c
@@ -53,8 +53,22 @@ tb_int_t xm_path_translate(lua_State *lua) {
}
// do path:translate()
- tb_char_t data[TB_PATH_MAXN];
- tb_size_t size = tb_path_translate_to(path, (tb_size_t)path_size, data, sizeof(data), normalize);
+ tb_char_t buff[TB_PATH_MAXN];
+ tb_char_t* data = buff;
+ tb_size_t maxn = sizeof(buff);
+ tb_size_t size = tb_path_translate_to(path, (tb_size_t)path_size, data, maxn, normalize);
+ if (!size) {
+ /* use a larger heap buffer for the long path to avoid stack buffer overflow,
+ * because tb_path_translate_to() does not truncate the output.
+ * https://github.com/xmake-io/xmake/issues/6962
+ *
+ * note: we cannot expand maxn for the `~` prefixed path,
+ * because tbox expands the home directory with an internal TB_PATH_MAXN buffer.
+ */
+ maxn = (tb_size_t)path_size + TB_PATH_MAXN;
+ data = (tb_char_t *)lua_newuserdata(lua, maxn);
+ size = tb_path_translate_to(path, (tb_size_t)path_size, data, maxn, normalize);
+ }
if (size) {
lua_pushlstring(lua, data, (size_t)size);
} else {
diff --git a/xmake/modules/private/service/remote_build/filesync.lua b/xmake/modules/private/service/remote_build/filesync.lua
index fa9ba1fde..d2c2d6703 100644
--- a/xmake/modules/private/service/remote_build/filesync.lua
+++ b/xmake/modules/private/service/remote_build/filesync.lua
@@ -89,7 +89,10 @@ function filesync:snapshot()
ignorefiles = "|" .. table.concat(ignorefiles, "|")
end
local count = 0
- for _, filepath in ipairs(os.files(path.join(rootdir, "**" .. ignorefiles))) do
+ -- we should not translate the whole pattern with ignorefiles in path.join,
+ -- because the joined pattern string may be very long (> TB_PATH_MAXN)
+ -- https://github.com/xmake-io/xmake/issues/6962
+ for _, filepath in ipairs(os.files(path.join(rootdir, "**") .. ignorefiles)) do
local fileitem = path.relative(filepath, rootdir)
if fileitem then
-- we should always use '/' in path key for supporting linux & windows