Skip to content

Plugins: zeron.fetch can return a font's or a picture's bytes whole, in base64 - #1379

Closed
hoangvu12 wants to merge 1 commit into
zeronsh:zeron/zgxfrom
hoangvu12:service-fetch-binary
Closed

hoangvu12 wants to merge 1 commit into
zeronsh:zeron/zgxfrom
hoangvu12:service-fetch-binary

Conversation

@hoangvu12

@hoangvu12 hoangvu12 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

zeron.fetch hands the body to Luau as String::from_utf8_lossy, so a font or a picture comes back with every non-UTF-8 byte turned into U+FFFD. A plugin can't download a Google Font or an image through its service.

Now zeron.fetch(url, { binary = true }) returns body as the bytes in base64. Results reach Luau as JSON, which carries only text, so base64 is the safe way across. The 16 MB cap and the default text body don't change.

local r = zeron.fetch("https://fonts.gstatic.com/s/inter/…/Inter.ttf", { binary = true }):await()
-- r.body: base64

Related: #1367 takes the result as zeron.load_font { base64 = r.body }, and zeronsh/zgx#2074 adds the same for a window's ui.load_font.

Testing

fetch_gives_bytes_in_base64_when_asked: a local server sends all 256 byte values plus NUL and 0x80. With binary the decoded body matches byte for byte. Without it, the body is the lossy text, as before. cargo test -p zeron-engine --lib plugins::service::tests::fetch passes on Windows, with getrusage in two test helpers stubbed locally (not in this PR).


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…se64

A body crossed into Luau as String::from_utf8_lossy, so every byte that
isn't UTF-8 became U+FFFD: a fetched TTF or PNG came back corrupted, and a
plugin had no way to download one. With { binary = true } the body is the
bytes in base64 (Luau gets results as JSON, which carries text only). The
default stays text.
@hoangvu12

Copy link
Copy Markdown
Contributor Author

Folded into #1392, which combines our plugin pull requests into one for review. This change is its commit 71a7407.

@hoangvu12 hoangvu12 closed this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant