Decode an untrusted image without trusting the decoder.
The application splits into a trusted Qt host and a disposable worker. The host chooses one file and opens it read-only. The worker receives that descriptor, invokes Qt’s native image parser, and returns a framebuffer through a framed UNIX socket.
927 x 965, ARGB32, decoded in a separate process.1. Give the worker code, not the filesystem
The image demo is compiled with emilua-genmain. The generator embeds init.lua and decoder.lua into the executable’s module cache, which subprocess actors inherit. emilua-genmods supplies the Qt and Easybox modules selected by the build.
This is a critical part of the boundary: removing general filesystem access does not remove the code the worker needs to run. The executable carries that code deliberately.
meson.build—track every embedded Lua source
main_cpp = custom_target(
'init.cpp',
depend_files : ['src/init.lua', 'src/decoder.lua'],
output : 'init.cpp',
command : [emilua_genmain, meson.current_source_dir() / 'src'],
capture : true,
)
Both files are explicit dependencies, so changing the worker regenerates the executable. The build also retains the libc-service library explicitly; its load-time registration is needed for mediated libc calls and must not be discarded by --as-needed.
2. Mediate library access without confusing compatibility with enforcement
Easybox applies operating-system restrictions. libc_service provides a compatibility path for selected libc calls that existing native libraries still make. The supervisor handles access checks for a small set of Qt-related directories; other requests fall back to the child’s restricted credentials.
src/init.lua—policy for existence checks
if master.function_ == 'access' then
local path = tostring(master:arguments())
if access_paths[path] ~= nil then
master:send(access_paths[path])
else
master:use_slave_credentials()
end
else
master:use_slave_credentials()
end
An access answer is not permission to open arbitrary files. The OS sandbox remains the enforcement layer. A new libc_service pair is created for every worker because the slave end is consumed when spawned.
3. Transfer only the selected file and a reply channel
A connected UNIX SOCK_SEQPACKET pair carries one framed response. The worker receives its end as a descriptor. The host closes its own copies after sending them.
src/init.lua—the complete capability handoff
local host_channel, worker_channel = unix.seqpacket.socket.pair()
worker_channel = worker_channel:release()
local input = fs.open(fs.path.new(path), {'read_only'})
worker:send{ input = input, output = worker_channel }
input:close()
worker_channel:close()
The worker has no need to know which other images exist. It receives one input and one output.
4. Parse in the worker
The worker reads through EOF, preserves non-EOF I/O errors, and then invokes Qt. The host never calls qt.decode_image() on untrusted bytes.
src/decoder.lua—the only parser invocation
local ok, result = pcall(qt.decode_image, data)
if ok then
-- Return the framebuffer as described below.
else
output:send(byte_span.append('ERROR\n', tostring(result)))
end
The Lua source is embedded, but Qt’s parser is native code. This is the distinction the homepage summarizes as create the compartment before invoking the risky parser.
5. Return metadata and pixels with explicit descriptor passing
qt.decode_image() returns width, height, a small framebuffer format, and a memfd. The worker sends a text frame plus that descriptor. Both send() and send_with_fds() require an actual byte_span, so the metadata string is converted explicitly.
src/decoder.lua—framed success response
local metadata = byte_span.append(string.format(
'OK\n%d\n%d\n%s', result.width, result.height, result.format))
output:send_with_fds(metadata, {result.memfd})
result.memfd:close()
The host parses only this small metadata frame and requires exactly one returned descriptor. It never follows pointers supplied by the parser.
6. Validate before display
The host reconstructs the result table and passes it to qt.image_from_decode_result(). That Qt helper accepts only supported framebuffer formats, validates the fields, seals the memfd, and maps the pixels for the UI.
src/init.lua—turn the response into a UI image
local result = decode(path)
local image = qt.image_from_decode_result(result)
result.memfd:close()
qml.property.img.image = image
The security boundary ends with simple validated data. The parser remains in its own process.
7. Verify success and failure
mise run build:image
mise run verify
# Decoder test output:
Decoded in a separate process: 927 x 965, ARGB32
One Meson test decodes the bundled PNG. Another presents src/init.lua as an image and requires a nonzero exit status. The CLI error path writes a diagnostic and calls system.exit(1) rather than allowing an uncaught Lua panic to masquerade as success.
Limits of the claim
This is a verified teaching example, not a production security audit. Review Easybox’s current policy, Kafel behavior, native-module loading rules, and the target OS before reuse. Qt’s image helpers are unavailable on Windows, and native-module descriptor loading has OS-specific requirements.