Preserve POSIX byte paths when resolving archive volumes

This commit is contained in:
Eremey Valetov committed 2026-11-07 08:43:04 -05:00
1 parent 960ab7b224
commit 418e4987f0
2 files changed
+28 -3

No files matched your search

+17 -3
View File
@@ -303,10 +303,8 @@ static PyObject *chunk_length(PyObject *module, PyObject *args)
uc2_chunker_next(&chunker, (const uint8_t *)data, (size_t)length, &offset, &size);
return PyLong_FromSize_t(size);
}
static PyObject *open_path(PyObject *module, PyObject *args)
static PyObject *open_path_impl(PyObject *module, const char *path)
{
const char *path;
if (!PyArg_ParseTuple(args, "s", &path)) return NULL;
char error[256];
FILE *stream;
Py_BEGIN_ALLOW_THREADS
@@ -355,6 +353,22 @@ static PyObject *open_path(PyObject *module, PyObject *args)
#endif
return result;
}
static PyObject *open_path(PyObject *module, PyObject *args)
{
#ifdef _WIN32
/* The Windows path opener explicitly converts UTF-8 to UTF-16. */
const char *path;
if (!PyArg_ParseTuple(args,"s",&path)) return NULL;
return open_path_impl(module,path);
#else
/* Preserve surrogateescaped filesystem bytes, including bytes paths. */
PyObject *encoded=NULL;
if (!PyArg_ParseTuple(args,"O&",PyUnicode_FSConverter,&encoded)) return NULL;
PyObject *result=open_path_impl(module,PyBytes_AS_STRING(encoded));
Py_DECREF(encoded);
return result;
#endif
}
static PyMethodDef module_methods[] = {
{"open_path", open_path, METH_VARARGS, "Open/reassemble SAS or UC2SEA input without executing it."},
{"chunk_length", chunk_length, METH_VARARGS, "First Gear chunk length (8 KiB target)."},
+11
View File
@@ -117,3 +117,14 @@ print('handles preserved')
cwd=tmp_path,capture_output=True,text=True)
assert result.returncode == 0, result.stderr
assert result.stdout.strip() == 'handles preserved'
@pytest.mark.skipif(__import__('os').name == 'nt', reason='POSIX byte filenames')
def test_non_utf8_volume_path(tmp_path):
import os
directory=tmp_path/os.fsdecode(b'volume-\xff')
directory.mkdir()
first=directory/'MORE.EXE'
shutil.copyfile(FIXTURES/'sea'/'MORE.EXE', first)
with UC2File(os.fsencode(first)) as archive:
assert archive.read('SUB/NOTE.TXT') == b'UC2SEA nested file\r\n'*17