From 4876f2b0fb44b49b275a6c814eecbb93e2b88bfa Mon Sep 17 00:00:00 2001 From: AO55 Date: Sun, 8 Nov 2026 01:46:55 -0300 Subject: [PATCH 1/3] [tracer] A zip's names are read as UTF-8, past one that is none ScarletNX's Share Log zip flags each name as UTF-8 (miniz does), and in the worker's C locale libarchive gives a name with an accent (a game's folder) as none, with ARCHIVE_WARN, which ended the walk through the zip there. The worker makes a UTF-8 locale before it shuts itself in, the names are read in it, and an entry with no name is passed by. Signed-off-by: AO55 --- docs/TESTING.md | 6 ++- docs/TRACER.md | 4 +- tracer/Makefile | 2 +- tracer/src/files.c | 38 ++++++++++++++++++- tracer/src/files.h | 7 +++- tracer/src/worker.c | 6 ++- tracer/tests/test_tracer.c | 77 +++++++++++++++++++++++++++++++++++++- 7 files changed, 131 insertions(+), 9 deletions(-) diff --git a/docs/TESTING.md b/docs/TESTING.md index ee2e2d7..54cf34b 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -47,7 +47,8 @@ usage. temporary folder: - the events and what a message asks; which files are logs, screenshots and videos; the logs unpacked from a `.gz` and - a `.zip`, and the name each downloads as from the site (a log's, never the archive's); the screenshots' metadata + a `.zip` (a name flagged UTF-8 read in the C locale, one that is no UTF-8 passed by), and the name each downloads as + from the site (a log's, never the archive's); the screenshots' metadata taken out (PNG, JPEG, WebP, GIF) and broken ones refused; an MP4's place and camera blanked; text made valid UTF-8; - the game a log names (and the older builds' titles, a garbled one, a name in another script); the crash report's dumps left out of a log as the log summary leaves them out; the games' names from the list (an update's and an @@ -71,7 +72,8 @@ temporary folder: one that never answers, one gone before it reads, one that names a host file, one shut in its folder that tries the site, the database and /etc/passwd, one that answers without having shut itself in, one that reads the bot's environment before the bot keeps it from its user's debuggers and not after, the bot's descriptors closed in it, no - worker for a message without files; + worker for a message without files, a Share Log zip whose names are flagged UTF-8 and have accents, read once shut + in; - the MCP server over that site: its handshake and protocol versions, notifications, broken and unknown requests, each tool's filters, limits and errors, and a query's 16 words at most; - runs of edenprobe: edenprobe's families and which lose their detail, the drivers by the ban table's names and by diff --git a/docs/TRACER.md b/docs/TRACER.md index 961dcfe..337d6e7 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -57,7 +57,9 @@ for it). The worker's answer is checked before any of its files moves from the w IPv4 address but the loopback's written as `[ip]` and each e-mail address as `[email]` (a network game's log names the player's address and the other players'), and summarized: the game, its title ID and version, the build, the system and GPU, how the run ended and where, the service commands and what else the runtime missed, the last lines. A file - that is no ScarletNX log, nor a run of edenprobe, is named in the reply and not kept. + that is no ScarletNX log, nor a run of edenprobe, is named in the reply and not kept. A zip's names are read as + UTF-8 whatever the worker's locale (ScarletNX's Share Log flags each name so), in a locale it makes before it shuts + itself in; an entry whose name it cannot read is passed by, and the walk goes on. - Its screenshots (PNG, JPEG, WebP, GIF or PPM, read from their bytes; 8 at most, 25 MiB each) lose their metadata: EXIF and its place and camera, XMP, PNG's text and time, JPEG's and GIF's comments, a GIF's applications' data but its loop, and what follows a JPEG's or a GIF's end (a phone's motion photo video, a maker's trailer). A PPM, the diff --git a/tracer/Makefile b/tracer/Makefile index 350ba41..e483f66 100644 --- a/tracer/Makefile +++ b/tracer/Makefile @@ -79,7 +79,7 @@ src/store.o: src/store.c src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) $(SQLITE_CFLAGS) -c -o $@ src/store.c src/site.o: src/site.c src/site.h src/files.h src/rules.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/site.c -src/worker.o: src/worker.c src/worker.h src/report.h src/age.h src/store.h src/probe.h src/tracer.h +src/worker.o: src/worker.c src/worker.h src/report.h src/files.h src/age.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/worker.c src/issues.o: src/issues.c src/issues.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/issues.c diff --git a/tracer/src/files.c b/tracer/src/files.c index 0a909a4..e7f2686 100644 --- a/tracer/src/files.c +++ b/tracer/src/files.c @@ -3,6 +3,7 @@ #include "files.h" #include #include +#include #include #include #include @@ -343,6 +344,32 @@ int tr_ppm_png(const char* data, size_t n, Buf* out) { return 0; } +/* the UTF-8 locale a zip's names are read in, made once and kept for the process's life; 0 where there is none */ +static locale_t utf8_locale(void) { + static locale_t utf8; + static int tried; + if (!tried) { + tried = 1; + utf8 = newlocale(LC_CTYPE_MASK, "C.UTF-8", (locale_t)0); + if (!utf8) utf8 = newlocale(LC_CTYPE_MASK, "en_US.UTF-8", (locale_t)0); + } + return utf8; +} +int tr_names_ready(void) { return utf8_locale() ? 0 : -1; } +/* a zip's names read as UTF-8 by the calling thread, whatever the process's locale: in a worker's, C, libarchive gives + no name at all for an entry its zip flags as UTF-8 (miniz flags each one ScarletNX's Share Log writes) when the name + is no ASCII (a game's folder named with an accent), and says ARCHIVE_WARN. The locale before, for names_back; 0 + where the system has no UTF-8 locale, the names then as libarchive gives them */ +static locale_t names_utf8(void) { + locale_t utf8 = utf8_locale(); + return utf8 ? uselocale(utf8) : (locale_t)0; +} +static void names_back(locale_t was) { + if (was) uselocale(was); +} +/* whether archive_read_next_header gave an entry: ARCHIVE_WARN is one too, a name it could not convert among them */ +static int entry(int got) { return got == ARCHIVE_OK || got == ARCHIVE_WARN; } + /* an archive of data read from memory, as a .zip or as a .gz of one file */ static struct archive* opened(int zip, const char* data, size_t n) { struct archive* a = archive_read_new(); @@ -360,7 +387,14 @@ static struct archive* opened(int zip, const char* data, size_t n) { return a; } +static int unpacked(const char* name, const char* data, size_t n, size_t max, Buf* out, char** why); int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out, char** why) { + locale_t was = names_utf8(); + int rc = unpacked(name, data, n, max, out, why); + names_back(was); + return rc; +} +static int unpacked(const char* name, const char* data, size_t n, size_t max, Buf* out, char** why) { int zip = ends(name, ".zip"), wanted = -1, at = 0; struct archive* a; struct archive_entry* e; @@ -381,7 +415,7 @@ int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out int text = -1, started = -1; size_t read = 0; if (!(a = opened(1, data, n))) goto broken; - for (at = 0; archive_read_next_header(a, &e) == ARCHIVE_OK; ++at) { + for (at = 0; entry(archive_read_next_header(a, &e)); ++at) { const char* inner = archive_entry_pathname(e); int marks, whole = 1; if (archive_entry_filetype(e) != AE_IFREG) continue; @@ -412,7 +446,7 @@ int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out wanted = started >= 0 ? started : text >= 0 ? text : wanted; } if (!(a = opened(zip, data, n))) goto broken; - for (at = 0; archive_read_next_header(a, &e) == ARCHIVE_OK; ++at) { + for (at = 0; entry(archive_read_next_header(a, &e)); ++at) { if (zip && at != wanted) continue; while ((got = archive_read_data(a, piece, sizeof piece)) > 0) { if ((size_t)got > max - out->len) { diff --git a/tracer/src/files.h b/tracer/src/files.h index 5d05a1f..6e5b5a6 100644 --- a/tracer/src/files.h +++ b/tracer/src/files.h @@ -35,8 +35,13 @@ int tr_ppm_png(const char* data, size_t n, Buf* out); /* a log as text: a .gz's or a .zip's unpacked, any other name's bytes as they are, max bytes at most. Of a .zip, the entry that holds a whole run of edenprobe (probe.h), else one a run begins in, else its first .log, .txt or .jsonl, - else its first file; its entries are read in looking for the run up to 256 MiB in all. 0, or -1 with why (owned) */ + else its first file; its entries are read in looking for the run up to 256 MiB in all. A zip's names are read as + UTF-8 whatever the process's locale. 0, or -1 with why (owned) */ int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out, char** why); +/* the UTF-8 locale a zip's names are read in, made now: before a worker shuts itself in its folder, where the locale's + files no longer open. 0, or -1 when the system has none (C.UTF-8, en_US.UTF-8): a zip's names that are no ASCII + are then lost */ +int tr_names_ready(void); /* the name the text tr_unpack made of name is saved as: a .gz's without its .gz ("game.log.gz" as "game.log"), with .log after it when what is left is no .log, .txt or .jsonl; a .zip's with .log for its .zip ("logs.zip" as "logs.log"); any other name as it is. The site keeps the text, never the archive. Owned */ diff --git a/tracer/src/worker.c b/tracer/src/worker.c index 386b7c1..d5ff4c1 100644 --- a/tracer/src/worker.c +++ b/tracer/src/worker.c @@ -28,6 +28,8 @@ #include #endif +#include "files.h" + #define QUESTION_MAX (1 << 20) /* the bytes of a question at most */ #define NAME_MAX_KEPT 200 /* the bytes of a file's name kept from an answer */ #define SKIPPED_MAX 4000 /* the bytes of the lines of the files not taken */ @@ -228,8 +230,10 @@ int wk_serve(FILE* in, FILE* out, TrGet get, void* ctx) { tr_message_free(&m); return 1; } - /* the downloads first, the network and the CA files still open to it; then it is shut in with what came */ + /* the downloads first, the network and the CA files still open to it, and the locale's files for a zip's names; + then it is shut in with what came */ tr_download(&t, &k, &m, dirfd, why); + if (tr_names_ready()) rei_log("no UTF-8 locale (C.UTF-8, en_US.UTF-8): a zip's names that are no ASCII are lost"); if (!(shut = wk_shut_in(dirfd, &failed))) { rei_log("the worker could not shut itself in its folder: %s", failed); for (i = 0; i < m.nfiles; ++i) { diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index 42704af..e9a7b59 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -158,6 +158,45 @@ static char* packed(int zip, const char* inner, const char* text, size_t* n) { return out; } +enum { ZIP_STORED = 1, ZIP_UTF8 = 2 }; +static unsigned le16_at(const char* p) { return (unsigned char)p[0] | (unsigned)(unsigned char)p[1] << 8; } +static unsigned long le32_at(const char* p) { return le16_at(p) | (unsigned long)le16_at(p + 2) << 16; } +/* a zip of n entries, entry i data[i]'s sizes[i] bytes (strlen's when sizes is NULL or it is 0): deflated or, with + ZIP_STORED, stored as they are (so that a test can find and break one's bytes); with ZIP_UTF8 each entry flagged as + holding a UTF-8 name (general purpose bit 11, in its central directory's record and its local header), as miniz + writes ScarletNX's Share Log, which libarchive writes in a UTF-8 locale alone. Its length */ +static size_t zip_bytes(char* out, size_t cap, const char* const* names, const char* const* data, const size_t* sizes, + int n, int how) { + struct archive* a = archive_write_new(); + size_t used = 0, at; + int i; + archive_write_set_format_zip(a); + if (how & ZIP_STORED) archive_write_set_format_option(a, "zip", "compression", "store"); + archive_write_open_memory(a, out, cap, &used); + for (i = 0; i < n; ++i) { + struct archive_entry* e = archive_entry_new(); + size_t len = sizes && sizes[i] ? sizes[i] : strlen(data[i]); + archive_entry_set_pathname_utf8(e, names[i]); + archive_entry_set_size(e, (la_int64_t)len); + archive_entry_set_filetype(e, AE_IFREG); + archive_entry_set_perm(e, 0644); + archive_write_header(a, e); + archive_write_data(a, data[i], len); + archive_entry_free(e); + } + archive_write_close(a); + archive_write_free(a); + if ((how & ZIP_UTF8) && used >= 22 && !memcmp(out + used - 22, "PK\5\6", 4)) { /* no comment: the end's 22 bytes */ + at = le32_at(out + used - 22 + 16); /* the central directory */ + for (i = 0; i < (int)le16_at(out + used - 22 + 10) && at + 46 <= used && !memcmp(out + at, "PK\1\2", 4); ++i) { + size_t local = le32_at(out + at + 42); + out[at + 9] |= 0x08; + if (local + 30 <= used && !memcmp(out + local, "PK\3\4", 4)) out[local + 7] |= 0x08; + at += 46 + le16_at(out + at + 28) + le16_at(out + at + 30) + le16_at(out + at + 32); + } + } + return used; +} static void test_message(void) { TrMessage m; const char* mention = @@ -526,6 +565,24 @@ static void test_unpack(void) { CHECK(!tr_unpack("plain.txt", "text", 4, TR_LOG_MAX, &out, &why) && out.len == 4); CHECK(tr_unpack("plain.txt", "text", 4, 3, &out, &why)); free(why); + { /* a Share Log zip as ScarletNX writes it, each name flagged UTF-8, a game's folder named with an accent before its + log: read through, in the C locale this test runs in as a worker does */ + static char zip[1 << 16]; + const char* names[] = {"games/Some G\xc3\xa1me [0100AAAABBBB0000]/old.dat", + "games/Some G\xc3\xa1me [0100AAAABBBB0000]/2026-11-07_21-45-11.log"}; + const char* texts[] = {"older bytes\n", LOG}; + size_t k; + n = zip_bytes(zip, sizeof zip, names, texts, NULL, 2, ZIP_UTF8); + CHECK(!tr_unpack("scarletnx-logs-2026-11-07_21-46-12.zip", zip, n, TR_LOG_MAX, &out, &why)); + CHECK(out.len == strlen(LOG) && !memcmp(out.text, LOG, out.len)); + /* and one flagged UTF-8 whose name is none (a byte 0xff), which libarchive gives with ARCHIVE_WARN: passed by */ + names[0] = "games/oldXname.dat"; + n = zip_bytes(zip, sizeof zip, names, texts, NULL, 2, ZIP_UTF8); + for (k = 0; k + 18 <= n; ++k) + if (!memcmp(zip + k, "games/oldXname.dat", 18)) zip[k + 9] = (char)0xff; + CHECK(!tr_unpack("logs.zip", zip, n, TR_LOG_MAX, &out, &why)); + CHECK(out.len == strlen(LOG) && !memcmp(out.text, LOG, out.len)); + } buf_free(&out); /* the name the unpacked text is saved as: never an archive's, as it is no archive any more */ { @@ -800,7 +857,8 @@ static void test_reports(void) { HAS(p, "

Report #1

"); /* the theme picker on every page, its links from the site's root however deep the page: the nginx answers them */ HAS(p, "\n\n
"); HAS(p, "something missed"); HAS(p, "
Missed
1 service command
"); @@ -2283,6 +2341,23 @@ static void test_worker(const char* self_path) { free(log); } CHECK(waiting_files() == 0); + { /* a Share Log zip through the worker, shut in its folder: its names flagged UTF-8 as miniz writes them, a game's + folder named with an accent, read in the UTF-8 locale it made before it shut itself in */ + static char zip[1 << 16]; + const char* names[] = {"games/Some G\xc3\xa1me [0100AAAABBBB0000]/old.dat", + "games/Some G\xc3\xa1me [0100AAAABBBB0000]/2026-11-07_21-45-11.log"}; + const char* data[] = {"older bytes\n", LOG}; + size_t n = zip_bytes(zip, sizeof zip, names, data, NULL, 2, ZIP_UTF8); + serve_file("https://cdn.discordapp.com/8/logs.zip", zip, n); + m = message(7008, 131, "<@99> a zip through the worker"); + attach(&m, "scarletnx-logs-2026-11-07_21-46-12.zip", "https://cdn.discordapp.com/8/logs.zip", (double)n); + t = answer_text(respond(&m)); + HAS(t, "1 log, 0 screenshots"); + free(t); + tr_message_free(&m); + CHECK(st_by_message(tracer.store, 7008) > 0); + CHECK(waiting_files() == 0); + } /* a worker that crashes, one that never answers, and one that names a host file: nothing kept, nothing left */ worker_argv[1] = "--crash"; m = message(7002, 132, "<@99>"); From bf6836432a07d96cfe5eceafbf1992587e1d4cd2 Mon Sep 17 00:00:00 2001 From: AO55 Date: Sun, 8 Nov 2026 01:47:56 -0300 Subject: [PATCH 2/3] [tracer] A zip's screenshots are kept, and a picture is never a log A player's Share Log zip (report 66) held five screenshots beside its logs, and Tracer kept the log alone. A .zip's screenshots are now kept beside its log, under their names, as attached ones are (a PPM as a PNG, their metadata out, 8 a report); a zip brings them to a report full of logs, and a file whose bytes are a picture is taken as one whatever its name says. A limit says what it cut: a file's size ("it is 30.2 MiB, over the 25 MiB a screenshot may be"), the names past the 8. An approved report's issue shows its screenshots as the site's pictures. scripts/test-rule-mutants.py becomes scripts/test-mutants.py, with this change's mutants beside the rules' (test_tracer --files runs its tests). Signed-off-by: AO55 --- .github/workflows/test.yml | 2 +- docs/TESTING.md | 24 ++- docs/TRACER.md | 33 ++- scripts/test-mutants.py | 278 ++++++++++++++++++++++++ scripts/test-rule-mutants.py | 157 -------------- tracer/src/files.c | 78 ++++++- tracer/src/files.h | 32 ++- tracer/src/issues.c | 17 ++ tracer/src/issues.h | 8 +- tracer/src/report.c | 194 ++++++++++++----- tracer/src/report.h | 19 +- tracer/tests/test_tracer.c | 403 +++++++++++++++++++++++++++++++---- 12 files changed, 957 insertions(+), 288 deletions(-) create mode 100755 scripts/test-mutants.py delete mode 100755 scripts/test-rule-mutants.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ed0a680..7c6e1e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: - run: sudo apt-get update -qq && sudo apt-get install -y -qq libcurl4-openssl-dev libsqlite3-dev libarchive-dev zlib1g-dev - run: make -C accordwimsy test - run: make -C tracer test - - run: python3 scripts/test-rule-mutants.py + - run: python3 scripts/test-mutants.py - run: sh scripts/test-install.sh - run: python3 scripts/test-check-docs.py - run: python3 scripts/check-docs.py diff --git a/docs/TESTING.md b/docs/TESTING.md index 54cf34b..248b139 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -17,7 +17,7 @@ What CI runs on each pull request and each push to main (`.github/workflows/test.yml`), with no network and no Discord: - make -C rei test && make -C accordwimsy test && make -C tracer test && python3 scripts/test-rule-mutants.py && + make -C rei test && make -C accordwimsy test && make -C tracer test && python3 scripts/test-mutants.py && sh scripts/test-install.sh && python3 scripts/test-check-docs.py && python3 scripts/check-docs.py && sh scripts/test-check-theme.sh && sh scripts/check-theme.sh @@ -47,9 +47,10 @@ usage. temporary folder: - the events and what a message asks; which files are logs, screenshots and videos; the logs unpacked from a `.gz` and - a `.zip` (a name flagged UTF-8 read in the C locale, one that is no UTF-8 passed by), and the name each downloads as - from the site (a log's, never the archive's); the screenshots' metadata - taken out (PNG, JPEG, WebP, GIF) and broken ones refused; an MP4's place and camera blanked; text made valid UTF-8; + a `.zip` (never one of its pictures, nor a Mac's fork; a name flagged UTF-8 read in the C locale, one that is no + UTF-8 passed by), and the name each downloads as from the site (a log's, never the archive's); a zip's screenshots + walked by name, without their folders, each read within its size; the screenshots' metadata taken out (PNG, JPEG, + WebP, GIF) and broken ones refused; an MP4's place and camera blanked; text made valid UTF-8; - the game a log names (and the older builds' titles, a garbled one, a name in another script); the crash report's dumps left out of a log as the log summary leaves them out; the games' names from the list (an update's and an add-on's ID, a report named at once, one named at the next start, a log's name first, a GBA game by its code, a @@ -61,7 +62,11 @@ temporary folder: naming the game), deletion by the sender and the guild's administrators and by no one else; a reply alone that makes a report of the message it replies to (its files, its author, its words, the hourly limit of the one who asked) and its refusals (another channel or server, a bot's message, one gone or kept from the bot, one without files as the - Message Content intent shows it, one that is a report already); + Message Content intent shows it, one that is a report already); a Share Log zip's screenshots kept beside its log + (by their names, a PPM as a PNG, their metadata out, a broken one and a Mac's fork named or left), twelve of them + past the room of eight, an update with no room left, a picture attached as a log taken as a screenshot, a zip that + brings screenshots to a report full of logs, one too large said with its size, one whose bytes fail the zip's check; + the issue's screenshots as the site's pictures; - a database of the first schema upgraded, a deleted message, a report's number never reused, the hourly limit, the JSON with no Discord id, the channels it answers in (a list, `all`, none, and other words refused); - the issues an approval files, through a fake GitHub: an administrator's reaction files one, a second files none, @@ -98,9 +103,12 @@ temporary folder: words, suite, failing or not) and `probe_case` (by key, by words, several, none, a key that is none), and gone with its reports; a case no run names any more losing its page. -`python3 scripts/test-rule-mutants.py` then changes `tracer/src/rules.c` one way at a time in a copy of the tree (a -threshold one off, a comparison that lets one more in, a condition left out: 19 mutants) and expects `test_tracer ---rules` to fail on each; a mutant it passes, or one whose text `rules.c` no longer has, fails it. About 10 s. +`python3 scripts/test-mutants.py` then changes Tracer's code one way at a time in a copy of the tree, and expects its +tests to fail on each: `tracer/src/rules.c` (a threshold one off, a comparison that lets one more in, a condition left +out: 19 mutants, `test_tracer --rules`); what a report keeps of its files, in `files.c`, `report.c` and `issues.c` (a +zip's screenshots, a picture never read as a log, the limits said with their values: 17 mutants, `test_tracer +--files`); and the worker's locale for a zip's names, made before it shuts itself in (1 mutant, +the whole suite). A mutant they pass, or one whose text its file no longer has once, fails it. About 30 s. `make -C tracer bench [RUNS=1000] [FOLDER=/tmp/tracer-bench]` (`tracer/tests/bench_probe.c`, built by `make test`, run by hand) keeps RUNS runs like edenprobe 0.9.0's graphics run (1069 cases) on fifteen machines in a new database in diff --git a/docs/TRACER.md b/docs/TRACER.md index 337d6e7..1893daa 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -57,13 +57,22 @@ for it). The worker's answer is checked before any of its files moves from the w IPv4 address but the loopback's written as `[ip]` and each e-mail address as `[email]` (a network game's log names the player's address and the other players'), and summarized: the game, its title ID and version, the build, the system and GPU, how the run ended and where, the service commands and what else the runtime missed, the last lines. A file - that is no ScarletNX log, nor a run of edenprobe, is named in the reply and not kept. A zip's names are read as + that is no ScarletNX log, nor a run of edenprobe, is named in the reply and not kept. Of a `.zip`, the log is the + entry [a run of edenprobe](#a-run-of-edenprobe) is in, else its first `.log`, `.txt` or `.jsonl`, else its first + file that is no picture or video; never one of its pictures, nor a Mac's `__MACOSX/` fork. A zip's names are read as UTF-8 whatever the worker's locale (ScarletNX's Share Log flags each name so), in a locale it makes before it shuts itself in; an entry whose name it cannot read is passed by, and the walk goes on. -- Its screenshots (PNG, JPEG, WebP, GIF or PPM, read from their bytes; 8 at most, 25 MiB each) lose their metadata: - EXIF and its place and camera, XMP, PNG's text and time, JPEG's and GIF's comments, a GIF's applications' data but - its loop, and what follows a JPEG's or a GIF's end (a phone's motion photo video, a maker's trailer). A PPM, the - frames ScarletNX's runtimes save (P6, 8 bits a channel), is kept as a PNG, which a browser shows. +- Its screenshots (PNG, JPEG, WebP, GIF or PPM, read from their bytes; 8 at most, 25 MiB each), attached or in a `.zip` + beside its log (each entry named `.png`, `.jpg`, `.jpeg`, `.webp`, `.gif` or `.ppm`, kept under its file's name + without the zip's folders; a Mac's `__MACOSX/` forks are none), lose their metadata: EXIF and its place and camera, + XMP, PNG's text and time, JPEG's and GIF's comments, a GIF's applications' data but its loop, and what follows a + JPEG's or a GIF's end (a phone's motion photo video, a maker's trailer). A PPM, the frames ScarletNX's runtimes save + (P6, 8 bits a channel; the capture key's `captures/screenshot_.ppm`), is kept as a PNG, which a browser shows. + A file whose bytes are a picture is taken as a screenshot, whatever its name says: it is never read as a log. The + reply names the screenshots past the 8 with that room (`shot_9.png, shot_10.png, shot_11.png and 2 more in + logs.zip: a report keeps 8 screenshots`), and one too large with its size (`huge.png in logs.zip: it is 30.2 MiB, over + the 25 MiB a screenshot may be`), as it does a log or a video; and, on a system with no UTF-8 locale, how many of a + zip's files had names it could not read. - Its videos (MP4 or WebM, read from their bytes; 2 at most, 100 MiB each) are played on the report's page. An MP4's place, time and camera (its udta and meta boxes whole, where a phone keeps them under its own keys, XMP's uuid box, and ©xyz, loci, ©mak and ©mod wherever else they are) are blanked where they are, as free boxes of zeros, so that @@ -91,7 +100,8 @@ for it). The worker's answer is checked before any of its files moves from the w A reply to any of a report's messages (the one that sent it, an update, Tracer's answer, also one it posted before it kept them, whose link names the report) that mentions Tracer adds its logs, screenshots, videos and words to it, as -`@Tracer add 12` does, within the same limits (3 logs and 8 screenshots a report). Only the person who sent the report, +`@Tracer add 12` does, within the same limits (3 logs and 8 screenshots a report; a `.zip` brings its screenshots while +the report has room for them, though its logs are full). Only the person who sent the report, the owner and administrators of the server it was sent in and `TRACER_ADMINS` add to it; anyone else is asked for a report of their own, which goes with the same game. A report its logs did not name takes the name a later log of the same title ID gives. Words added later are shown under the report's note, each with its date. @@ -159,7 +169,8 @@ When the log summary or the list of names changes (`scripts/sync-logscan.sh`, `s report keeps of its logs (`TR_FACTS`), the next start summarizes each kept log again, draws each report's facts again from its first log, files a report whose first log now names another game under that game, names one its logs don't name from the list, makes a report whose first log holds a run of edenprobe the run's, and takes out of each kept log -what a run's lines would say of the player. +what a run's lines would say of the player. A report keeps no zip, only its log and +screenshots: a zip's screenshots sent before Tracer read them are not found again, and are added by a reply with them. ## Commands @@ -179,8 +190,10 @@ A report becomes a GitHub issue once a server's administrator approves it: with administrator of the server it was sent in (or one of `TRACER_ADMINS`) reacts to one of its messages (the one that sent it, an update, Tracer's answer) with the approval's emoji, `TRACER_ISSUES_EMOJI`, the check mark by default. Tracer opens the issue in that repository with what the site shows of the report: its facts and its first log's summary (home -folders as `~`, addresses as `[ip]` and `[email]`, no dumps), each of a log's or a player's words in a code block, -where GitHub links no `@name` and no `#number`, and the report's page. The issue's number goes into the database, onto +folders as `~`, addresses as `[ip]` and `[email]`, no dumps), each of a log's or a player's words in a code block, where +GitHub links no `@name` and no `#number`, the report's page, and its screenshots, each the site's picture 320 pixels wide linked to it and named by its number in the report (a file's +name is a player's words). GitHub's API takes no file for an issue: its image proxy fetches each picture from the site, +so the site must answer it. The issue's number goes into the database, onto the report's page and its JSON, and into a short reply on Discord. A report is filed once: a second approval opens no other issue, and one GitHub refused (its status and message in the reply) is tried again by the next approval. Anyone else's reaction, and another emoji, are left as they are. GitHub is asked from the bot's own process, with a 30 s @@ -257,7 +270,7 @@ Static files, drawn again where a report changes them, and all of them at each s | `index.html` | each game, its latest outcome, its reports' count; a search and a filter by outcome | | `all.html` | every report, the newest first | | `g/.html` | a game's reports: `` its title ID, or `n-` and its name's letters for a game known by name | -| `r//` | a report: its facts, screenshots, and each log with its summary, to read or download (a log sent in a `.zip` or a `.gz` is kept as its text and downloads as one: `logs.zip` as `logs.log`, `game.log.gz` as `game.log`); a run of edenprobe's has its counts and each case that did not pass | +| `r//` | a report: its facts, its screenshots (each shown small, and opened whole by a click), and each log with its summary, to read or download (a log sent in a `.zip` or a `.gz` is kept as its text and downloads as one: `logs.zip` as `logs.log`, `game.log.gz` as `game.log`); a run of edenprobe's has its counts and each case that did not pass | | `probe/index.html` | the runs of edenprobe: the machines (an emulator, a driver and its version, a system), each case that fails somewhere with its results on each machine, each suite's, and each run | | `probe/c/.html` | a case of edenprobe: `` 16 hex digits of its suite and name; its results on each machine, what the rules say of it, and its newest 200 failures and skips with their detail | | `probe/d/.html` | a driver, by the ban table's name (`radv`, `nvidia`; `unknown` for the console's reports): its machines, the cases that fail on it, its ban candidates, its runs | diff --git a/scripts/test-mutants.py b/scripts/test-mutants.py new file mode 100755 index 0000000..c03ebde --- /dev/null +++ b/scripts/test-mutants.py @@ -0,0 +1,278 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-or-later +# Copyright 2026 the ScarletNX contributors +"""Tracer's code that decides, changed one way at a time, each change a mutant that its tests must fail: the rules over +the runs of edenprobe (tracer/src/rules.c, tests run as test_tracer --rules: a threshold one off, a comparison that +lets one more in, a condition left out), and which files a report keeps and what of them (tracer/src/files.c, +report.c and issues.c, tests run as test_tracer --files: a zip's screenshots, a picture never read as a log, the +limits said with their values; the worker's locale for a zip's names, by the whole suite). A mutant the tests pass is a rule nothing holds. Each runs in a copy of the tree in a temporary folder; the +checkout is never written. + + python3 scripts/test-mutants.py [--root DIR] [--cc CC] + +Exit 0 when every mutant was caught; 1 when one survived, or one's text is no longer in its file once (said with +which).""" + +import argparse +import os +import shutil +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +# each mutant of rules.c: what it does, the text it changes (found once), and what it becomes +RULES = ( + ( + 'two failing reports make a candidate', + 'if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE)', + 'if (fails < RULE_FAIL_REPORTS - 1 || people < RULE_FAIL_PEOPLE)', + ), + ( + 'one person makes a candidate', + 'if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE)', + 'if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE - 1)', + ), + ( + 'each failing report is another person', + 'for (k = 0; k < people && posters[k] != who; ++k) continue;', + 'k = people;', + ), + ( + 'two passing reports clear the driver', + 'if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS)', + 'if (npass < RULE_PASS_REPORTS - 1 || drivers < RULE_PASS_DRIVERS)', + ), + ( + 'one other driver clears it', + 'if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS)', + 'if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS - 1)', + ), + ( + 'a passing build eight days after counts', + 'near = gap <= RULE_DAYS * 86400.0 && gap >= -RULE_DAYS * 86400.0;', + 'near = gap <= (RULE_DAYS + 1) * 86400.0 && gap >= -RULE_DAYS * 86400.0;', + ), + ( + 'a passing build eight days before counts', + 'near = gap <= RULE_DAYS * 86400.0 && gap >= -RULE_DAYS * 86400.0;', + 'near = gap <= RULE_DAYS * 86400.0 && gap >= -(RULE_DAYS + 1) * 86400.0;', + ), + ('the failing driver clears itself', 'run->p.driver_id == d || e[j].result != ST_PASS', 'e[j].result != ST_PASS'), + ('a passing version does not end the range', 'if (vp) break;', 'if (vp && 0) break;'), + ( + 'another system joins the range', + 'if (scarletnx(p) && p->driver_id == d && !strcmp(p->os, os) &&', + 'if (scarletnx(p) && p->driver_id == d && os &&', + ), + ( + "Eden's failures count", + 'if (scarletnx(p) && p->driver_id == d && !strcmp(p->os, os) &&', + 'if (p->driver_id == d && !strcmp(p->os, os) &&', + ), + ('a mixed end is not said', 'c->mixed |= c->high && on[j].result == ST_FAIL;', 'c->mixed |= 0;'), + ( + "four drivers make it ScarletNX's", + 'if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 2 && failing == nd)))', + 'if (!(failing >= RULE_GENERAL_DRIVERS + 1 || (nd >= 2 && failing == nd)))', + ), + ( + "one driver seen makes it ScarletNX's", + 'if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 2 && failing == nd)))', + 'if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 1 && failing == nd)))', + ), + ( + "Eden's drivers count as seen", + 'if (!scarletnx(p) || p->driver_id <= 0 || (e[i].result != ST_PASS', + 'if (p->driver_id <= 0 || (e[i].result != ST_PASS', + ), + ( + "ScarletNX's own failure is a candidate too", + 'if (!general(out, &gcap, results[i].name, e + a, b - a))', + 'if (general(out, &gcap, results[i].name, e + a, b - a) || 1)', + ), + ( + 'a build that passes and fails passed', + 'if (last >= 0 && last < nb - 1 && b[last].passes && !b[last].fails)', + 'if (last >= 0 && last < nb - 1 && b[last].passes)', + ), + ( + 'a newest build that passes once fails', + 'last >= 0 && b[last].fails && !b[last].passes; --last', + 'last >= 0 && b[last].fails; --last', + ), + ( + 'a -dirty build is a build', + 'strcmp(q->os, p->os) || !published(q->commit) || q->built <= 0 ||', + 'strcmp(q->os, p->os) || !published(q->commit ? "0000000" : NULL) || q->built <= 0 ||', + ), +) + +# each mutant of what a report keeps: what it does, the file under tracer/src, its text (found once), what it becomes +FILES = ( + ( + 'a picture in a zip can be its log', + 'files.c', + 'if (inner && (named(inner) == TR_IMAGE || named(inner) == TR_VIDEO)) continue;', + 'if (inner && named(inner) == TR_VIDEO) continue;', + ), + ( + "a Mac's fork can be a zip's log", + 'files.c', + 'if (archive_entry_filetype(e) != AE_IFREG || (inner && mac_fork(inner))) continue;', + 'if (archive_entry_filetype(e) != AE_IFREG) continue;', + ), + ( + "a Mac's fork is a screenshot", + 'files.c', + 'if (mac_fork(path) || named(path) != TR_IMAGE) continue;', + 'if (named(path) != TR_IMAGE) continue;', + ), + ('a PPM is no picture by its name', 'files.c', '".webp", ".gif", ".ppm"};', '".webp", ".gif"};'), + ( + "a screenshot keeps its zip's folders", + 'files.c', + "for (leaf = path + strlen(path); leaf > path && leaf[-1] != '/' && leaf[-1] != '\\\\'; --leaf) continue;", + 'leaf = path;', + ), + ( + "a zip's names are read in the worker's locale, C", + 'files.c', + 'return utf8 ? uselocale(utf8) : (locale_t)0;', + 'return utf8 ? (locale_t)0 : (locale_t)0;', + ), + ( + 'a name libarchive could not convert ends the walk', + 'files.c', + 'static int entry(int got) { return got == ARCHIVE_OK || got == ARCHIVE_WARN; }', + 'static int entry(int got) { return got == ARCHIVE_OK; }', + ), + ( + 'a picture of its max exactly is refused', + 'files.c', + ' if ((size_t)got > max - out->len) {\n buf_free(out);\n return 1;', + ' if ((size_t)got >= max - out->len) {\n buf_free(out);\n return 1;', + ), + ( + 'a picture one byte past its max is read', + 'files.c', + ' if ((size_t)got > max - out->len) {\n buf_free(out);\n return 1;', + ' if ((size_t)got > max - out->len + 1) {\n buf_free(out);\n return 1;', + ), + ( + "a zip's screenshots are not taken", + 'report.c', + 'if (zip_named(a->name)) take_zip_images(k, dirfd, a->name, &got, !logged);', + 'if (0 && zip_named(a->name)) take_zip_images(k, dirfd, a->name, &got, !logged);', + ), + ( + 'a picture attached as a log is read as one', + 'report.c', + 'if (tr_image_ext(text.text, text.len)) { /* a picture, whatever its name says: never read as a log */', + 'if (0) {', + ), + ( + "a zip's screenshots go past the room", + 'report.c', + ' if (full(k, TR_IMAGE)) {\n if (more++ < 3)', + ' if (0) {\n if (more++ < 3)', + ), + ('the screenshots past the room are not said', 'report.c', ' if (more) {', ' if (0) {'), + ( + 'a zip is not downloaded once its logs are full', + 'report.c', + 'if (kind == TR_LOG && zip_named(a->name) && !full(k, TR_IMAGE)) return NULL;', + 'if (0 && kind == TR_LOG && zip_named(a->name) && !full(k, TR_IMAGE)) return NULL;', + ), + ("a zip's log is read once the logs are full", 'report.c', 'int logged = !full(k, TR_LOG);', 'int logged = 1;'), + ( + "a screenshot's size is not said", + 'report.c', + 'return rei_format("it is %.1f MiB, over the %zu MiB a %s may be", bytes / (1 << 20), max_of(kind) >> 20,', + 'return rei_format("over %.0f%zu MiB%s", bytes * 0, max_of(kind) >> 20,', + ), + ( + 'the issue has no screenshots', + 'issues.c', + ' shots(&b, r->id, files, nfiles, url);', + ' if (0) shots(&b, r->id, files, nfiles, url);', + ), +) + +# what only the whole suite holds: the worker, a process of its own shut in its folder (test_worker) +WORKER = ( + ( + "the worker makes a zip's locale once shut in, where its files do not open", + 'worker.c', + ' if (tr_names_ready()) rei_log(', + ' if (0 && tr_names_ready()) rei_log(', + ), +) + +# each group: its mutants, as (what, file, old, new), and test_tracer's arguments for the tests that must catch them +GROUPS = ( + (tuple((what, 'rules.c', old, new) for what, old, new in RULES), ['--rules']), + (FILES, ['--files']), + (WORKER, []), +) + + +def run(cmd, cwd): + # a failing check may print a picture's bytes: they are read as text all the same + return subprocess.run( + cmd, check=False, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, errors='replace' + ) + + +def main(): + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + ap.add_argument('--root', type=Path, default=ROOT, help='the tree (the checkout this script is in)') + ap.add_argument('--cc', default=os.environ.get('CC', 'cc'), help='the compiler (CC, else cc)') + args = ap.parse_args() + with tempfile.TemporaryDirectory(prefix='tracer-mutants-') as tmp: + tree = Path(tmp) + for part in ('rei', 'tracer'): + shutil.copytree( + args.root / part, + tree / part, + ignore=shutil.ignore_patterns('*.o', 'test_tracer', 'tracer', 'tracer-mcp'), + ) + work = tree / 'tracer' + # without -Werror: a mutant often leaves a helper or a variable unused, which says nothing of what it tests + make = ['make', '-s', 'tests/test_tracer', 'CC=' + args.cc, 'CFLAGS=-O0 -g', 'WARN=-std=c99'] + built = run(make, work) + for _, tests in GROUPS: + if built.returncode or run(['./tests/test_tracer', *tests], work).returncode: + print( + f'the tree as it is does not build or pass test_tracer {" ".join(tests)}:\n' + built.stdout, + file=sys.stderr, + ) + return 1 + failed = count = 0 + for mutants, tests in GROUPS: + for what, name, old, new in mutants: + source = work / 'src' / name + original = source.read_text() + count += 1 + if original.count(old) != 1: + print(f'stale: {what}: {name} has "{old}" {original.count(old)} times, not once') + failed = 1 + continue + source.write_text(original.replace(old, new)) + built = run(make, work) + if built.returncode: + print(f'stale: {what}: the mutant does not build:\n{built.stdout}') + failed = 1 + elif run(['./tests/test_tracer', *tests], work).returncode: + print(f'killed: {what}') + else: + print(f'SURVIVED: {what}') + failed = 1 + source.write_text(original) + print(f'{count} mutants, {"one or more left" if failed else "every one caught"}') + return failed + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/scripts/test-rule-mutants.py b/scripts/test-rule-mutants.py deleted file mode 100755 index afa1737..0000000 --- a/scripts/test-rule-mutants.py +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-3.0-or-later -# Copyright 2026 the ScarletNX contributors -"""Tracer's rules over the runs of edenprobe (tracer/src/rules.c) changed one way at a time, each change a mutant that -its tests (tracer/tests/test_tracer.c's test_rules, run as test_tracer --rules) must fail: a threshold one off, a -comparison that lets one more in, a condition left out. A mutant the tests pass is a rule nothing holds. Each runs in -a copy of the tree in a temporary folder; the checkout is never written. - - python3 scripts/test-rule-mutants.py [--root DIR] [--cc CC] - -Exit 0 when every mutant was caught; 1 when one survived, or one's text is no longer in rules.c (said with which).""" - -import argparse -import os -import shutil -import subprocess -import sys -import tempfile -from pathlib import Path - -ROOT = Path(__file__).resolve().parents[1] -# each mutant: what it does, the text of rules.c it changes (found once), and what it becomes -MUTANTS = ( - ( - 'two failing reports make a candidate', - 'if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE)', - 'if (fails < RULE_FAIL_REPORTS - 1 || people < RULE_FAIL_PEOPLE)', - ), - ( - 'one person makes a candidate', - 'if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE)', - 'if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE - 1)', - ), - ( - 'each failing report is another person', - 'for (k = 0; k < people && posters[k] != who; ++k) continue;', - 'k = people;', - ), - ( - 'two passing reports clear the driver', - 'if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS)', - 'if (npass < RULE_PASS_REPORTS - 1 || drivers < RULE_PASS_DRIVERS)', - ), - ( - 'one other driver clears it', - 'if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS)', - 'if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS - 1)', - ), - ( - 'a passing build eight days after counts', - 'near = gap <= RULE_DAYS * 86400.0 && gap >= -RULE_DAYS * 86400.0;', - 'near = gap <= (RULE_DAYS + 1) * 86400.0 && gap >= -RULE_DAYS * 86400.0;', - ), - ( - 'a passing build eight days before counts', - 'near = gap <= RULE_DAYS * 86400.0 && gap >= -RULE_DAYS * 86400.0;', - 'near = gap <= RULE_DAYS * 86400.0 && gap >= -(RULE_DAYS + 1) * 86400.0;', - ), - ('the failing driver clears itself', 'run->p.driver_id == d || e[j].result != ST_PASS', 'e[j].result != ST_PASS'), - ('a passing version does not end the range', 'if (vp) break;', 'if (vp && 0) break;'), - ( - 'another system joins the range', - 'if (scarletnx(p) && p->driver_id == d && !strcmp(p->os, os) &&', - 'if (scarletnx(p) && p->driver_id == d && os &&', - ), - ( - "Eden's failures count", - 'if (scarletnx(p) && p->driver_id == d && !strcmp(p->os, os) &&', - 'if (p->driver_id == d && !strcmp(p->os, os) &&', - ), - ('a mixed end is not said', 'c->mixed |= c->high && on[j].result == ST_FAIL;', 'c->mixed |= 0;'), - ( - "four drivers make it ScarletNX's", - 'if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 2 && failing == nd)))', - 'if (!(failing >= RULE_GENERAL_DRIVERS + 1 || (nd >= 2 && failing == nd)))', - ), - ( - "one driver seen makes it ScarletNX's", - 'if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 2 && failing == nd)))', - 'if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 1 && failing == nd)))', - ), - ( - "Eden's drivers count as seen", - 'if (!scarletnx(p) || p->driver_id <= 0 || (e[i].result != ST_PASS', - 'if (p->driver_id <= 0 || (e[i].result != ST_PASS', - ), - ( - "ScarletNX's own failure is a candidate too", - 'if (!general(out, &gcap, results[i].name, e + a, b - a))', - 'if (general(out, &gcap, results[i].name, e + a, b - a) || 1)', - ), - ( - 'a build that passes and fails passed', - 'if (last >= 0 && last < nb - 1 && b[last].passes && !b[last].fails)', - 'if (last >= 0 && last < nb - 1 && b[last].passes)', - ), - ( - 'a newest build that passes once fails', - 'last >= 0 && b[last].fails && !b[last].passes; --last', - 'last >= 0 && b[last].fails; --last', - ), - ( - 'a -dirty build is a build', - 'strcmp(q->os, p->os) || !published(q->commit) || q->built <= 0 ||', - 'strcmp(q->os, p->os) || !published(q->commit ? "0000000" : NULL) || q->built <= 0 ||', - ), -) - - -def run(cmd, cwd): - return subprocess.run(cmd, check=False, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) - - -def main(): - ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) - ap.add_argument('--root', type=Path, default=ROOT, help='the tree (the checkout this script is in)') - ap.add_argument('--cc', default=os.environ.get('CC', 'cc'), help='the compiler (CC, else cc)') - args = ap.parse_args() - with tempfile.TemporaryDirectory(prefix='tracer-mutants-') as tmp: - tree = Path(tmp) - for part in ('rei', 'tracer'): - shutil.copytree( - args.root / part, - tree / part, - ignore=shutil.ignore_patterns('*.o', 'test_tracer', 'tracer', 'tracer-mcp'), - ) - work = tree / 'tracer' - rules = work / 'src' / 'rules.c' - original = rules.read_text() - make = ['make', '-s', 'tests/test_tracer', 'CC=' + args.cc, 'CFLAGS=-O0 -g'] - built = run(make, work) - if built.returncode or run(['./tests/test_tracer', '--rules'], work).returncode: - print('the tree as it is does not build or pass its rules tests:\n' + built.stdout, file=sys.stderr) - return 1 - failed = 0 - for what, old, new in MUTANTS: - if original.count(old) != 1: - print(f'stale: {what}: rules.c has "{old}" {original.count(old)} times, not once') - failed = 1 - continue - rules.write_text(original.replace(old, new)) - built = run(make, work) - if built.returncode: - print(f'stale: {what}: the mutant does not build:\n{built.stdout}') - failed = 1 - elif run(['./tests/test_tracer', '--rules'], work).returncode: - print(f'killed: {what}') - else: - print(f'SURVIVED: {what}') - failed = 1 - rules.write_text(original) - print(f'{len(MUTANTS)} mutants, {"one or more left" if failed else "every one caught"}') - return failed - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/tracer/src/files.c b/tracer/src/files.c index e7f2686..a6c140b 100644 --- a/tracer/src/files.c +++ b/tracer/src/files.c @@ -18,8 +18,12 @@ static int ends(const char* name, const char* ext) { size_t n = strlen(name), e = strlen(ext); return n > e && !strcasecmp(name + n - e, ext); } +/* a zip's entry under __MACOSX/: the resource fork a Mac's zip keeps beside each file ("__MACOSX/._shot.png"), none + of the player's files */ +static int mac_fork(const char* path) { return !strncmp(path, "__MACOSX/", 9); } -TrKind tr_kind(const char* name, const char* type) { +/* a file's kind by its name alone, TR_OTHER for a name tr_kind knows no extension of */ +static TrKind named(const char* name) { static const char* const logs[] = {".log", ".txt", ".jsonl", ".gz", ".zip"}; static const char* const images[] = {".png", ".jpg", ".jpeg", ".webp", ".gif", ".ppm"}; static const char* const videos[] = {".mp4", ".m4v", ".webm"}; @@ -30,6 +34,12 @@ TrKind tr_kind(const char* name, const char* type) { if (ends(name, images[i])) return TR_IMAGE; for (i = 0; i < sizeof videos / sizeof *videos; ++i) if (ends(name, videos[i])) return TR_VIDEO; + return TR_OTHER; +} + +TrKind tr_kind(const char* name, const char* type) { + TrKind kind = named(name); + if (kind != TR_OTHER) return kind; if (!strncmp(type, "image/", 6)) return TR_IMAGE; if (!strncmp(type, "video/", 6)) return TR_VIDEO; if (!strncmp(type, "text/plain", 10)) return TR_LOG; @@ -411,14 +421,17 @@ static int unpacked(const char* name, const char* data, size_t n, size_t max, Bu return 0; } if (zip) { /* an entry holding a whole run of edenprobe, else one a run begins in, else the first .log, .txt or - .jsonl, else the first file: a Share Log zip holds many logs, one of which may be the run */ - int text = -1, started = -1; + .jsonl, else the first file that is no picture or video: a Share Log zip holds many logs, one of + which may be the run, and the screenshots a player puts beside them */ + int text = -1, started = -1, files = 0; size_t read = 0; if (!(a = opened(1, data, n))) goto broken; for (at = 0; entry(archive_read_next_header(a, &e)); ++at) { const char* inner = archive_entry_pathname(e); int marks, whole = 1; - if (archive_entry_filetype(e) != AE_IFREG) continue; + if (archive_entry_filetype(e) != AE_IFREG || (inner && mac_fork(inner))) continue; + files = 1; + if (inner && (named(inner) == TR_IMAGE || named(inner) == TR_VIDEO)) continue; if (wanted < 0) wanted = at; if (!inner || (!ends(inner, ".log") && !ends(inner, ".txt") && !ends(inner, ".jsonl"))) continue; if (text < 0) text = at; @@ -440,7 +453,7 @@ static int unpacked(const char* name, const char* data, size_t n, size_t max, Bu archive_read_free(a); buf_free(out); if (wanted < 0) { - *why = rei_format("%s holds no file", name); + *why = rei_format(files ? "%s holds no log, only pictures or videos" : "%s holds no file", name); return -1; } wanted = started >= 0 ? started : text >= 0 ? text : wanted; @@ -468,6 +481,61 @@ static int unpacked(const char* name, const char* data, size_t n, size_t max, Bu return -1; } +int tr_zip_images(TrZipImages* z, const char* data, size_t n) { + memset(z, 0, sizeof *z); + z->size = -1; + return (z->a = opened(1, data, n)) ? 0 : -1; +} + +int tr_zip_next(TrZipImages* z) { + struct archive_entry* e; + locale_t was = names_utf8(); + int got; + free(z->name); + z->name = NULL; + while (entry(got = archive_read_next_header(z->a, &e))) { + const char *path = archive_entry_pathname(e), *leaf; + if (archive_entry_filetype(e) != AE_IFREG) continue; + if (!path) { /* a file whose name the zip does not give: none can say it is a picture */ + ++z->unnamed; + continue; + } + if (mac_fork(path) || named(path) != TR_IMAGE) continue; + for (leaf = path + strlen(path); leaf > path && leaf[-1] != '/' && leaf[-1] != '\\'; --leaf) continue; + z->name = tr_utf8(leaf, strlen(leaf)); + z->size = archive_entry_size_is_set(e) ? (double)archive_entry_size(e) : -1; + names_back(was); + return 1; + } + z->broken = got != ARCHIVE_EOF; + names_back(was); + return 0; +} + +int tr_zip_read(TrZipImages* z, size_t max, Buf* out) { + char piece[65536]; + la_ssize_t got; + buf_free(out); + while ((got = archive_read_data(z->a, piece, sizeof piece)) > 0) { + if ((size_t)got > max - out->len) { + buf_free(out); + return 1; + } + buf_addn(out, piece, (size_t)got); + } + if (got < 0) { + buf_free(out); + return -1; + } + return 0; +} + +void tr_zip_done(TrZipImages* z) { + if (z->a) archive_read_free(z->a); + free(z->name); + memset(z, 0, sizeof *z); +} + char* tr_unpacked_name(const char* name) { size_t n = strlen(name); if (ends(name, ".zip")) return rei_format("%.*s.log", (int)(n - 4), name); diff --git a/tracer/src/files.h b/tracer/src/files.h index 6e5b5a6..8b973c6 100644 --- a/tracer/src/files.h +++ b/tracer/src/files.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: GPL-3.0-or-later Copyright 2026 the ScarletNX contributors */ /* The bytes of the files a report keeps: which attachment is a log and which a screenshot, a log unpacked from its .gz - or .zip, a screenshot's kind read from its bytes and its metadata (camera, place, time, text) taken out, and text - made valid UTF-8 for the site */ + or .zip and the screenshots beside it in the .zip, a screenshot's kind read from its bytes and its metadata (camera, + place, time, text) taken out, and text made valid UTF-8 for the site */ #ifndef TR_FILES_H #define TR_FILES_H #include "tracer.h" @@ -35,13 +35,35 @@ int tr_ppm_png(const char* data, size_t n, Buf* out); /* a log as text: a .gz's or a .zip's unpacked, any other name's bytes as they are, max bytes at most. Of a .zip, the entry that holds a whole run of edenprobe (probe.h), else one a run begins in, else its first .log, .txt or .jsonl, - else its first file; its entries are read in looking for the run up to 256 MiB in all. A zip's names are read as - UTF-8 whatever the process's locale. 0, or -1 with why (owned) */ + else its first file that is no picture or video by its name (tr_kind's); its entries are read in looking for the run + up to 256 MiB in all. An entry under __MACOSX/, the resource fork a Mac's zip keeps beside each file, is none of the + player's. A zip's names are read as UTF-8 whatever the process's locale. 0, or -1 with why (owned) */ int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out, char** why); + /* the UTF-8 locale a zip's names are read in, made now: before a worker shuts itself in its folder, where the locale's files no longer open. 0, or -1 when the system has none (C.UTF-8, en_US.UTF-8): a zip's names that are no ASCII - are then lost */ + are then lost, said in the reply of each zip whose screenshots are */ int tr_names_ready(void); + +/* a .zip's screenshots, one at a time: its entries named as tr_kind's pictures are (.png, .jpg, .jpeg, .webp, .gif, + .ppm), in the zip's order, but those under __MACOSX/ */ +struct archive; +typedef struct { + struct archive* a; + char* name; /* owned: the entry's file name, valid UTF-8, without its folders (a zip made by hand may name the + player's) */ + double size; /* its bytes unpacked as the zip says, -1 when it does not */ + int broken; /* 1 once the zip stopped short of its end */ + int unnamed; /* the files passed by whose names the zip gave in no form this system reads */ +} TrZipImages; +/* z opened on the n bytes of a zip: 0, or -1 (nothing owned) for bytes no zip reader opens */ +int tr_zip_images(TrZipImages* z, const char* data, size_t n); +/* the next screenshot's entry: 1 with z->name and z->size, or 0 at the zip's end (z->broken when it stopped short) */ +int tr_zip_next(TrZipImages* z); +/* that entry's bytes into out (cleared first), max at most: 0, 1 for an entry that unpacks to more (out empty), -1 for + one that does not unpack */ +int tr_zip_read(TrZipImages* z, size_t max, Buf* out); +void tr_zip_done(TrZipImages* z); /* the name the text tr_unpack made of name is saved as: a .gz's without its .gz ("game.log.gz" as "game.log"), with .log after it when what is left is no .log, .txt or .jsonl; a .zip's with .log for its .zip ("logs.zip" as "logs.log"); any other name as it is. The site keeps the text, never the archive. Owned */ diff --git a/tracer/src/issues.c b/tracer/src/issues.c index aacf9f7..4402a6d 100644 --- a/tracer/src/issues.c +++ b/tracer/src/issues.c @@ -122,6 +122,22 @@ static size_t ticks(const char* text) { return most; } +/* the report's screenshots in the issue as its page shows them: each the site's image, 320 pixels wide, that links to + it, as the issue holds no file of its own (GitHub's API takes none; its image proxy fetches each from the site). The + text is "Screenshot N", N its number in the report: a file's name is a player's words, outside a code block */ +static void shots(Buf* b, long id, const StFile* files, int nfiles, const char* url) { + int i, any = 0; + for (i = 0; i < nfiles; ++i) { + const char* path = files[i].path; + if (strcmp(files[i].kind, "image") || !path || !*path || + strspn(path, "0123456789.abcdefghijklmnopqrstuvwxyz") != strlen(path)) + continue; + if (!any++) buf_add(b, "\nScreenshots, as the report's page shows them:\n\n"); + buf_printf(b, "\"Screenshot\n", + url, id, path, url, id, path, files[i].n); + } +} + char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const char* url) { Buf facts = {0}, b = {0}; const StFile* log = NULL; @@ -180,6 +196,7 @@ char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const ch for (i = 0; i < (int)fence; ++i) buf_add(&b, "`"); buf_add(&b, "\n\nThe log's home folders are written as ~ and its addresses as [ip] and [email]; the crash report's " "dumps of the game's bytes are not in it.\n"); + shots(&b, r->id, files, nfiles, url); buf_free(&facts); cJSON_Delete(s); return buf_take(&b); diff --git a/tracer/src/issues.h b/tracer/src/issues.h index cb3cfa5..29d76cc 100644 --- a/tracer/src/issues.h +++ b/tracer/src/issues.h @@ -2,7 +2,7 @@ Copyright 2026 the ScarletNX contributors */ /* A report filed as a GitHub issue once an administrator of its server approves it, reacting to one of its messages with the approval's emoji: the issue holds what the site shows of it (its facts and its first log's summary, home - folders as ~, no dumps, no addresses) and the report's page. Asked of GitHub from the bot's own process (the worker + folders as ~, no dumps, no addresses, its screenshots as the site's) and the report's page. Asked of GitHub from the bot's own process (the worker never holds a token), once a report */ #ifndef TR_ISSUES_H #define TR_ISSUES_H @@ -28,9 +28,9 @@ void tr_issues_free(TrIssues* is); /* the start's line saying them, every value but the token's; owned */ char* tr_issues_said(const TrIssues* is); -/* report r's issue: its title, and its body of what the site shows (files' summaries, its page at url), each of a - log's or a player's words in a code block, where GitHub links no @name and no #number, and no "#" before the - report's own number; owned */ +/* report r's issue: its title, and its body of what the site shows (files' summaries, its page at url, its screenshots + as the site's images linked to them), each of a log's or a player's words in a code block, where GitHub links no + @name and no #number, and no "#" before the report's own number; owned */ char* tr_issue_title(const StReport* r); char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const char* url); /* the issue opened: 0 with *number and *url (owned, its page on GitHub), or -1 with why (owned): GitHub's status and diff --git a/tracer/src/report.c b/tracer/src/report.c index 30cd583..831bd23 100644 --- a/tracer/src/report.c +++ b/tracer/src/report.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "common/utilities/demangle.h" @@ -234,8 +235,8 @@ static cJSON* help(void) { return embed( "Tracer", "Mention me with a ScarletNX log attached (.log, .txt, .gz or .zip), and screenshots if you have " - "them. I keep them as a report on the site, grouped by game. The log says which game it is: when it " - "does not, write the game's name in the message.\n\n" + "them, attached or in the .zip. I keep them as a report on the site, grouped by game. The log says which " + "game it is: when it does not, write the game's name in the message.\n\n" "A run of edenprobe is a report of its own, apart from the games: ScarletNX's log of the run (alone, or in " "the Share Log zip), Eden's log of it, or its report.jsonl (the console's, as it names no machine). The " "detail of its service, net and pad cases is left out, as it can name you.\n\n" @@ -334,6 +335,113 @@ static int stash(Taken* k, int dirfd, const char* data, size_t n) { return 0; } +/* what a file of kind may weigh at most, and what it is called in a reply */ +static size_t max_of(TrKind kind) { + return kind == TR_LOG ? TR_LOG_MAX : kind == TR_VIDEO ? TR_VIDEO_MAX : TR_IMAGE_MAX; +} +static const char* kind_word(TrKind kind) { return kind == TR_LOG ? "log" : kind == TR_VIDEO ? "video" : "screenshot"; } +/* why a file of kind that weighs bytes is not kept: "it is 30.2 MiB, over the 25 MiB a screenshot may be"; owned */ +static char* too_big(TrKind kind, double bytes) { + return rei_format("it is %.1f MiB, over the %zu MiB a %s may be", bytes / (1 << 20), max_of(kind) >> 20, + kind_word(kind)); +} + +/* a screenshot, named name in the report; zip names the .zip it came in, for the reply, NULL for one attached */ +static void take_image(Taken* k, int dirfd, const char* name, const char* zip, Buf* got) { + const char* ext = tr_image_ext(got->text, got->len); + char* said = zip ? rei_format("%s in %s", name, zip) : rei_strdup(name); + size_t n; + StFile* f; + if (ext && !strcmp(ext, "ppm")) { /* a frame ScarletNX saved, as a PNG a browser shows */ + Buf png = {0}; + if (tr_ppm_png(got->text, got->len, &png)) { + skip(k, said, "a PPM that isn't whole, or of more than 255 a channel"); + free(said); + return; + } + buf_free(got); + *got = png; + ext = "png"; + } + n = ext ? tr_strip_image(got->text, got->len) : 0; + if (!n) + skip(k, said, "not a PNG, JPEG, WebP, GIF or PPM image"); + else if (stash(k, dirfd, got->text, n)) + skip(k, said, "it could not be written down"); + else { + f = &k->files[k->n]; + f->n = k->base + k->n + 1; + strcpy(f->kind, "image"); + f->name = rei_strdup(name); + f->path = rei_format("%d.%s", f->n, ext); + f->bytes = (double)n; + ++k->n; + ++k->images; + } + free(said); +} + +/* why the report has no room left for one more of kind, given what it had and what this message kept; NULL for room */ +static const char* full(const Taken* k, TrKind kind) { + if (kind == TR_LOG && k->logs_had + k->logs >= TR_LOGS) return "a report keeps 3 logs"; + if (kind == TR_VIDEO && k->videos_had + k->videos >= TR_VIDEOS) return "a report keeps 2 videos"; + if (kind == TR_IMAGE && k->images_had + k->images >= TR_IMAGES) return "a report keeps 8 screenshots"; + return NULL; +} + +/* the screenshots in the .zip a log came in, each taken as one attached is, under its entry's file name; those past + the report's room named in one line with that room, as a zip may hold many. A zip that does not open is said when + unsaid, as its log was not read */ +static void take_zip_images(Taken* k, int dirfd, const char* zip, const Buf* got, int unsaid) { + TrZipImages z; + Buf over = {0}; + int more = 0; + if (tr_zip_images(&z, got->text, got->len)) { + if (unsaid) skip(k, zip, "it could not be unpacked"); + return; + } + while (tr_zip_next(&z)) { + Buf image = {0}; + char *said = rei_format("%s in %s", z.name, zip), *why; + if (full(k, TR_IMAGE)) { + if (more++ < 3) buf_printf(&over, "%s%s", over.len ? ", " : "", z.name); + } else if (z.size > (double)TR_IMAGE_MAX) { + why = too_big(TR_IMAGE, z.size); + skip(k, said, why); + free(why); + } else + switch (tr_zip_read(&z, TR_IMAGE_MAX, &image)) { + case 0: take_image(k, dirfd, z.name, zip, &image); break; + case 1: + why = rei_format("it unpacks to over the %zu MiB a screenshot may be", TR_IMAGE_MAX >> 20); + skip(k, said, why); + free(why); + break; + default: skip(k, said, "it could not be unpacked"); break; + } + buf_free(&image); + free(said); + } + if (more) { + char *names = more > 3 ? rei_format("%s and %d more in %s", over.text, more - 3, zip) + : rei_format("%s in %s", over.text, zip), + *why = rei_format("a report keeps %d screenshots", TR_IMAGES); + skip(k, names, why); + free(why); + free(names); + } + if (z.broken) skip(k, zip, "it could not be unpacked to its end: no screenshot after that point is kept"); + if (z.unnamed) { + char* why = rei_format("%d of its files have names this system cannot read: none of them is kept as a " + "screenshot", + z.unnamed); + skip(k, zip, why); + free(why); + } + buf_free(&over); + tr_zip_done(&z); +} + static void take_log(Taken* k, int dirfd, const TrAttachment* a, Buf* got) { Buf text = {0}; char *why = NULL, *tilded, *shown, *summary, *cut; @@ -351,6 +459,18 @@ static void take_log(Taken* k, int dirfd, const TrAttachment* a, Buf* got) { skip(k, a->name, "it is empty"); return; } + if (tr_image_ext(text.text, text.len)) { /* a picture, whatever its name says: never read as a log */ + if (full(k, TR_IMAGE)) + skip(k, a->name, full(k, TR_IMAGE)); + else if (text.len > TR_IMAGE_MAX) { + why = too_big(TR_IMAGE, (double)text.len); + skip(k, a->name, why); + free(why); + } else + take_image(k, dirfd, a->name, NULL, &text); + buf_free(&text); + return; + } tilded = snx_logscan_tilde(text.text, text.len, &n); buf_free(&text); if (!tilded) { @@ -408,39 +528,6 @@ static void take_log(Taken* k, int dirfd, const TrAttachment* a, Buf* got) { ++k->logs; } -static void take_image(Taken* k, int dirfd, const TrAttachment* a, Buf* got) { - const char* ext = tr_image_ext(got->text, got->len); - size_t n; - if (ext && !strcmp(ext, "ppm")) { /* a frame ScarletNX saved, as a PNG a browser shows */ - Buf png = {0}; - if (tr_ppm_png(got->text, got->len, &png)) { - skip(k, a->name, "a PPM that isn't whole, or of more than 255 a channel"); - return; - } - buf_free(got); - *got = png; - ext = "png"; - } - n = ext ? tr_strip_image(got->text, got->len) : 0; - StFile* f; - if (!n) { - skip(k, a->name, "not a PNG, JPEG, WebP, GIF or PPM image"); - return; - } - if (stash(k, dirfd, got->text, n)) { - skip(k, a->name, "it could not be written down"); - return; - } - f = &k->files[k->n]; - f->n = k->base + k->n + 1; - strcpy(f->kind, "image"); - f->name = rei_strdup(a->name); - f->path = rei_format("%d.%s", f->n, ext); - f->bytes = (double)n; - ++k->n; - ++k->images; -} - /* an MP4 or a WebM, an MP4's place and camera blanked */ static void take_video(Taken* k, int dirfd, const TrAttachment* a, Buf* got) { const char* ext = tr_video_ext(got->text, got->len); @@ -474,15 +561,17 @@ static char* kept(const Taken* k, const char* more) { /* attachment a's kind and the bytes it may have at most */ static TrKind kind_of(const TrAttachment* a, size_t* max) { TrKind kind = tr_kind(a->name, a->type); - *max = kind == TR_LOG ? TR_LOG_MAX : kind == TR_VIDEO ? TR_VIDEO_MAX : TR_IMAGE_MAX; + *max = max_of(kind); return kind; } -/* why the report has no room left for one more of kind, given what it had and what this message kept; NULL for room */ -static const char* full(const Taken* k, TrKind kind) { - if (kind == TR_LOG && k->logs_had + k->logs >= TR_LOGS) return "a report keeps 3 logs"; - if (kind == TR_VIDEO && k->videos_had + k->videos >= TR_VIDEOS) return "a report keeps 2 videos"; - if (kind == TR_IMAGE && k->images_had + k->images >= TR_IMAGES) return "a report keeps 8 screenshots"; - return NULL; +static int zip_named(const char* name) { + size_t n = strlen(name); + return n > 4 && !strcasecmp(name + n - 4, ".zip"); +} +/* why attachment a has no room in the report, NULL for room: a .zip has room while its log or its screenshots do */ +static const char* no_room(const Taken* k, const TrAttachment* a, TrKind kind) { + if (kind == TR_LOG && zip_named(a->name) && !full(k, TR_IMAGE)) return NULL; + return full(k, kind); } void tr_download(Tracer* t, Taken* k, const TrMessage* m, int dirfd, char* why[TR_FILES]) { @@ -498,12 +587,12 @@ void tr_download(Tracer* t, Taken* k, const TrMessage* m, int dirfd, char* why[T why[i] = NULL; if (kind == TR_OTHER) why[i] = rei_strdup("not a log or a screenshot"); - else if (full(k, kind)) /* full before this message: nothing of that kind is downloaded */ - why[i] = rei_strdup(full(k, kind)); + else if (no_room(k, a, kind)) /* full before this message: nothing of that kind is downloaded */ + why[i] = rei_strdup(no_room(k, a, kind)); else if (!from_discord(a->url)) why[i] = rei_strdup("not a file on Discord"); else if (a->size > (double)max) - why[i] = rei_format("over %zu MiB", max >> 20); + why[i] = too_big(kind, a->size); else if (t->get(t->ctx, a->url, max, &got, &failed)) { rei_log("a download failed: %s", failed ? failed : "no reason given"); why[i] = rei_strdup("the download failed"); @@ -535,7 +624,7 @@ void tr_read(Taken* k, const TrMessage* m, int dirfd, char* why[TR_FILES]) { const TrAttachment* a = &m->files[i]; size_t max; TrKind kind = kind_of(a, &max); - const char* no = why[i] ? why[i] : full(k, kind); + const char* no = why[i] ? why[i] : no_room(k, a, kind); char name[16], piece[65536]; Buf got = {0}; ssize_t r = 0; @@ -552,12 +641,17 @@ void tr_read(Taken* k, const TrMessage* m, int dirfd, char* why[TR_FILES]) { if (!no && (fd < 0 || r < 0 || got.len > max)) no = "it could not be read back"; if (no) skip(k, a->name, no); - else if (kind == TR_LOG) - take_log(k, dirfd, a, &got); - else if (kind == TR_VIDEO) + else if (kind == TR_LOG) { + int logged = !full(k, TR_LOG); /* else a .zip, for its screenshots alone */ + if (logged) + take_log(k, dirfd, a, &got); + else + skip(k, a->name, full(k, TR_LOG)); + if (zip_named(a->name)) take_zip_images(k, dirfd, a->name, &got, !logged); + } else if (kind == TR_VIDEO) take_video(k, dirfd, a, &got); else - take_image(k, dirfd, a, &got); + take_image(k, dirfd, a->name, NULL, &got); buf_free(&got); free(why[i]); why[i] = NULL; diff --git a/tracer/src/report.h b/tracer/src/report.h index dfef97e..37de27f 100644 --- a/tracer/src/report.h +++ b/tracer/src/report.h @@ -1,8 +1,9 @@ /* SPDX-License-Identifier: GPL-3.0-or-later Copyright 2026 the ScarletNX contributors */ -/* What Tracer does with a message that mentions it: a report made of its logs and screenshots (downloaded, the logs' - home folders shown as ~, their summaries made, the screenshots' metadata taken out), kept in the database and the - site's folder; "delete N" and "help" answered. Each answer is an embed for a reply */ +/* What Tracer does with a message that mentions it: a report made of its logs and screenshots (downloaded, a .zip's + screenshots beside its log, the logs' home folders shown as ~, their summaries made, the screenshots' metadata taken + out), kept in the database and the site's folder; "delete N" and "help" answered. Each answer is an embed for a + reply */ #ifndef TR_REPORT_H #define TR_REPORT_H #include "age.h" @@ -57,15 +58,15 @@ struct Tracer { void* discord_ctx; }; -/* m's attachments downloaded through t's get and read: the logs unpacked, their home folders as ~, their dumps and - addresses left out and summarized, the screenshots' metadata taken out; each kept one written into k->dir, each - other named in k->skipped */ +/* m's attachments downloaded through t's get and read: the logs unpacked (a .zip's screenshots taken beside its log), + their home folders as ~, their dumps and addresses left out and summarized, the screenshots' metadata taken out; + each kept one written into k->dir, each other named in k->skipped */ void tr_take(Tracer* t, Taken* k, const TrMessage* m); /* tr_take's two halves, which a worker splits by shutting itself in its folder between them (wk_shut_in): m's attachments downloaded through t's get into the folder dirfd (k->dir), attachment i as "in.", or why[i] (owned) - says why it is not (not a log or a screenshot, the report full of its kind, not on Discord, over its size, the - download failed); then each one read back from there and taken as tr_take takes it, its input removed, the others - named in k->skipped (why[] freed) */ + says why it is not (not a log or a screenshot, the report full of its kind (a .zip only when full of logs and of + screenshots), not on Discord, over its size (its size said), the download failed); then each one read back from + there and taken as tr_take takes it, its input removed, the others named in k->skipped (why[] freed) */ void tr_download(Tracer* t, Taken* k, const TrMessage* m, int dirfd, char* why[TR_FILES]); void tr_read(Taken* k, const TrMessage* m, int dirfd, char* why[TR_FILES]); /* k's files that were not moved into the site removed, with k->dir, and the rest freed */ diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index e9a7b59..0d5c57e 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -89,7 +89,7 @@ typedef struct { const char* data; size_t n; } Served; -static Served served[32]; +static Served served[64]; static int nserved, downloads; static void serve(const char* url, const char* data, size_t n) { if (nserved == (int)(sizeof served / sizeof *served)) { /* room for more: a test past it wrote over what follows */ @@ -197,6 +197,18 @@ static size_t zip_bytes(char* out, size_t cap, const char* const* names, const c } return used; } +static size_t chunk(char* to, const char* type, const char* data, size_t n); +/* a PNG whose text chunk says said (under 200 bytes), as a phone's or an editor's would: its length */ +static size_t small_png(char* to, const char* said) { + size_t n = 8; + memcpy(to, "\x89PNG\r\n\x1a\n", 8); + n += chunk(to + n, "IHDR", "0123456789abc", 13); + n += chunk(to + n, "tEXt", said, strlen(said)); + n += chunk(to + n, "IDAT", "pixels", 6); + n += chunk(to + n, "IEND", "", 0); + return n; +} + static void test_message(void) { TrMessage m; const char* mention = @@ -565,6 +577,30 @@ static void test_unpack(void) { CHECK(!tr_unpack("plain.txt", "text", 4, TR_LOG_MAX, &out, &why) && out.len == 4); CHECK(tr_unpack("plain.txt", "text", 4, 3, &out, &why)); free(why); + { /* a zip's log is none of its pictures, whatever else it holds, nor a Mac's resource fork */ + static char zip[1 << 16]; + char png[128]; + size_t npng = small_png(png, "x"); + const char* names[] = {"shot.png", "clip.mp4", "__MACOSX/._notes.dat", "notes.dat"}; + const char* bytes[] = {png, "a video", "\0\5\26\7fork", "some notes\n"}; + const size_t sizes[] = {npng, 0, 8, 0}; + const char* forked[] = {"__MACOSX/._game.log", "game.log"}; + const char* texts[] = {"the fork's bytes\n", LOG}; + n = zip_bytes(zip, sizeof zip, names, bytes, sizes, 4, 0); + CHECK(!tr_unpack("logs.zip", zip, n, TR_LOG_MAX, &out, &why)); + SAME(out.text, "some notes\n"); + n = zip_bytes(zip, sizeof zip, names, bytes, sizes, 3, 0); + CHECK(tr_unpack("logs.zip", zip, n, TR_LOG_MAX, &out, &why)); + SAME(why, "logs.zip holds no log, only pictures or videos"); + free(why); + n = zip_bytes(zip, sizeof zip, names + 2, bytes + 2, sizes + 2, 1, 0); + CHECK(tr_unpack("logs.zip", zip, n, TR_LOG_MAX, &out, &why)); + SAME(why, "logs.zip holds no file"); + free(why); + n = zip_bytes(zip, sizeof zip, forked, texts, NULL, 2, 0); + CHECK(!tr_unpack("logs.zip", zip, n, TR_LOG_MAX, &out, &why)); + CHECK(out.len == strlen(LOG) && !memcmp(out.text, LOG, out.len)); + } { /* a Share Log zip as ScarletNX writes it, each name flagged UTF-8, a game's folder named with an accent before its log: read through, in the C locale this test runs in as a worker does */ static char zip[1 << 16]; @@ -605,6 +641,59 @@ static void test_unpack(void) { } } +/* a zip's screenshots: by their names, in its order, without their folders, a Mac's forks and other files left out, + each read within the bytes it may have */ +static void test_zip_images(void) { + static char zip[1 << 16]; + char png[128]; + size_t npng = small_png(png, "x"), n, cut; + const char* names[] = {"summary.txt", + "captures/screenshot_1.png", + "__MACOSX/captures/._screenshot_1.png", + "frame.PPM", + "clip.mp4", + "captura_\xc3\xa9.JPG", + "old/notes.log", + "deep/er/back.gif"}; + const char* data[] = {"text\n", png, "fork", "P6\n1 1\n255\nRGB", "a video", "\xff\xd8\xff jpeg", + "a log\n", "GIF89a"}; + const size_t sizes[] = {0, npng, 0, 0, 0, 0, 0, 0}; + TrZipImages z; + Buf out = {0}; + n = zip_bytes(zip, sizeof zip, names, data, sizes, 8, ZIP_UTF8); + CHECK(!tr_zip_images(&z, zip, n)); + CHECK(tr_zip_next(&z) == 1); + SAME(z.name, "screenshot_1.png"); + CHECK(z.size == (double)npng); + CHECK(!tr_zip_read(&z, TR_IMAGE_MAX, &out) && out.len == npng && !memcmp(out.text, png, npng)); + CHECK(tr_zip_next(&z) == 1); + SAME(z.name, "frame.PPM"); + CHECK(tr_zip_read(&z, 13, &out) == 1 && !out.len); /* 14 bytes, one past its max: none of them */ + CHECK(tr_zip_next(&z) == 1); + SAME(z.name, "captura_\xc3\xa9.JPG"); /* its UTF-8 name, in the C locale a worker runs in */ + CHECK(tr_zip_next(&z) == 1); /* the one before not read: passed by */ + SAME(z.name, "back.gif"); + CHECK(!tr_zip_read(&z, 6, &out) && out.len == 6); /* its max exactly */ + CHECK(!tr_zip_next(&z) && !z.name && !z.broken); + tr_zip_done(&z); + CHECK(tr_zip_images(&z, "not a zip at all", 16) == -1); + /* a zip cut short in its second picture: the first whole, the second unread, the end said */ + { + const char* two[] = {"a.png", "b.png"}; + const char* pngs[] = {png, png}; + const size_t both[] = {npng, npng}; + n = zip_bytes(zip, sizeof zip, two, pngs, both, 2, ZIP_STORED); + for (cut = 30; cut < n && memcmp(zip + cut, "b.png", 5); ++cut) continue; /* b.png's local header's name */ + CHECK(cut < n); + CHECK(!tr_zip_images(&z, zip, cut + 5 + 20)); + CHECK(tr_zip_next(&z) == 1 && !tr_zip_read(&z, TR_IMAGE_MAX, &out) && out.len == npng); + if (tr_zip_next(&z) == 1) CHECK(tr_zip_read(&z, TR_IMAGE_MAX, &out) == -1); + CHECK(!tr_zip_next(&z) && z.broken); + tr_zip_done(&z); + } + buf_free(&out); +} + /* the log's summary as the bot makes it, owned */ static char* summarized(const char* text, size_t n) { SnxLogScan* s = calloc(1, sizeof *s); @@ -925,7 +1014,7 @@ static void test_reports(void) { HAS(t, "notes.txt: not a ScarletNX log"); HAS(t, "gone.log: the download failed"); HAS(t, "elsewhere.log: not a file on Discord"); - HAS(t, "huge.log: over 64 MiB"); + HAS(t, "huge.log: it is 953.7 MiB, over the 64 MiB a log may be"); free(t); tr_message_free(&m); @@ -2342,20 +2431,28 @@ static void test_worker(const char* self_path) { } CHECK(waiting_files() == 0); { /* a Share Log zip through the worker, shut in its folder: its names flagged UTF-8 as miniz writes them, a game's - folder named with an accent, read in the UTF-8 locale it made before it shut itself in */ + folder and a screenshot named with an accent, read in the UTF-8 locale it made before it shut itself in */ static char zip[1 << 16]; - const char* names[] = {"games/Some G\xc3\xa1me [0100AAAABBBB0000]/old.dat", - "games/Some G\xc3\xa1me [0100AAAABBBB0000]/2026-11-07_21-45-11.log"}; - const char* data[] = {"older bytes\n", LOG}; - size_t n = zip_bytes(zip, sizeof zip, names, data, NULL, 2, ZIP_UTF8); + const char* names[] = {"games/Some G\xc3\xa1me [0100AAAABBBB0000]/2026-11-07_21-45-11.log", + "captura_\xc3\xa9.png", "screenshot_20261107_214134.png"}; + const char* data[] = {LOG, png, png}; + const size_t sizes[] = {0, npng, npng}; + size_t n = zip_bytes(zip, sizeof zip, names, data, sizes, 3, ZIP_UTF8); + StReport r; + StFile* files; + int nfiles; serve_file("https://cdn.discordapp.com/8/logs.zip", zip, n); m = message(7008, 131, "<@99> a zip through the worker"); attach(&m, "scarletnx-logs-2026-11-07_21-46-12.zip", "https://cdn.discordapp.com/8/logs.zip", (double)n); t = answer_text(respond(&m)); - HAS(t, "1 log, 0 screenshots"); + HAS(t, "1 log, 2 screenshots"); + LACKS(t, "cannot read"); free(t); tr_message_free(&m); - CHECK(st_by_message(tracer.store, 7008) > 0); + CHECK(st_get(tracer.store, st_by_message(tracer.store, 7008), &r, &files, &nfiles) == 1 && nfiles == 3); + if (nfiles == 3) SAME(files[1].name, "captura_\xc3\xa9.png"); + st_report_free(&r); + st_files_free(files, nfiles); CHECK(waiting_files() == 0); } /* a worker that crashes, one that never answers, and one that names a host file: nothing kept, nothing left */ @@ -2928,6 +3025,218 @@ static void test_archive_download(void) { tr_message_free(&m); } +/* the screenshots a player puts in the launcher's Share Log zip, beside its logs (report 66's: five PNGs at its root): + kept with the log, by their entry's names, a PPM as a PNG, metadata out, past the report's room named with that + room; a picture never read as a log; on the issue as the site's images */ +static void test_zip_reports(void) { + static char share[1 << 16], many[1 << 16], more[1 << 16], late[1 << 16], big[1 << 16], broken[1 << 16]; + static char game_log[sizeof LOG + 512], png[128], photo[128], names_of[12][16]; + static const char ppm[] = "P6\n2 2\n255\nRGBrgbRGBrgb"; + size_t npng = small_png(png, "GPS 52.1N"), nphoto = small_png(photo, "a photo"), n; + TrMessage m; + StReport r; + StFile* files; + int nfiles, i; + long a, b; + char *t, *p, *rel; + snprintf(game_log, sizeof game_log, "%s", LOG); + { /* the Share Log zip: the game's log first, the launcher's, five pictures at its root (one a PPM in a folder, one + no picture at all), a Mac's fork, the summary */ + const char* names[] = {"games/Some G\xc3\xa1me [0100AAAABBBB0000]/2026-11-07_21-45-11.log", + "launcher/last-run.log", + "screenshot_20261107_214134.png", + "screenshot_20261107_214311.png", + "captures/screenshot_20261107_214321.ppm", + "__MACOSX/._screenshot_20261107_214134.png", + "broken.png", + "summary.txt"}; + const char* data[] = {game_log, "the run's output\n", png, photo, ppm, "fork", "no picture", "== summary ==\n"}; + const size_t sizes[] = {0, 0, npng, nphoto, sizeof ppm - 1, 0, 0, 0}; + n = zip_bytes(share, sizeof share, names, data, sizes, 8, ZIP_UTF8); /* as miniz writes it */ + serve("https://cdn.discordapp.com/66/scarletnx-logs-2026-11-07_21-46-12.zip", share, n); + } + m = message(9900, 990, "<@99> images in .zip"); + attach(&m, "scarletnx-logs-2026-11-07_21-46-12.zip", + "https://cdn.discordapp.com/66/scarletnx-logs-2026-11-07_21-46-12.zip", (double)n); + t = answer_text(respond(&m)); + HAS(t, "1 log, 3 screenshots"); + HAS(t, "broken.png in scarletnx-logs-2026-11-07_21-46-12.zip: not a PNG, JPEG, WebP, GIF or PPM image"); + LACKS(t, "._screenshot"); + free(t); + tr_message_free(&m); + a = st_by_message(tracer.store, 9900); + CHECK(st_get(tracer.store, a, &r, &files, &nfiles) == 1); + CHECK(nfiles == 4); + if (nfiles == 4) { + SAME(files[0].kind, "log"); + SAME(files[1].name, "screenshot_20261107_214134.png"); + SAME(files[1].path, "2.png"); + SAME(files[2].name, "screenshot_20261107_214311.png"); + SAME(files[3].name, "screenshot_20261107_214321.ppm"); + SAME(files[3].path, "4.png"); + } + st_report_free(&r); + st_files_free(files, nfiles); + rel = rei_format("r/%ld/1.log", a); + p = page(rel); + HAS(p, "ScarletNX - Some Game"); /* the game's log, no picture */ + LACKS(p, "\x89PNG"); + free(p); + free(rel); + rel = rei_format("%s/r/%ld/2.png", site, a); + p = read_file(rel, &n); + CHECK(p && n > 8 && !memcmp(p, "\x89PNG", 4) && !found(p, n, "GPS")); + free(p); + free(rel); + rel = rei_format("%s/r/%ld/4.png", site, a); + p = read_file(rel, NULL); + CHECK(p && !memcmp(p, "\x89PNG", 4)); + free(p); + free(rel); + rel = rei_format("r/%ld/index.html", a); + p = page(rel); + HAS(p, "

Screenshots

"); + HAS(p, "\"screenshot_20261107_214134.png\""); + HAS(p, "\"screenshot_20261107_214321.ppm\"");\\\"Screenshot", + a, a); + HAS(gh_body, p); + free(p); + p = rei_format("r/%ld/4.png\\\" width=\\\"320\\\" alt=\\\"Screenshot 4\\\">", a); + HAS(gh_body, p); + free(p); + LACKS(gh_body, "screenshot_20261107"); /* a file's name is a player's words: outside the code block, none */ + } + + /* twelve pictures: eight kept, the rest named in one line with the room; an update with two more, no room left */ + { + const char* names[13]; + const char* data[13]; + size_t sizes[13]; + names[0] = "scarletnx.log"; + data[0] = game_log; + sizes[0] = 0; + for (i = 0; i < 12; ++i) { + snprintf(names_of[i], sizeof names_of[i], "shot_%d.png", i + 1); + names[i + 1] = names_of[i]; + data[i + 1] = png; + sizes[i + 1] = npng; + } + n = zip_bytes(many, sizeof many, names, data, sizes, 13, 0); + serve("https://cdn.discordapp.com/66/many.zip", many, n); + n = zip_bytes(more, sizeof more, names + 1, data + 1, sizes + 1, 2, 0); + serve("https://cdn.discordapp.com/66/more.zip", more, n); + } + m = message(9901, 990, "<@99>"); + attach(&m, "many.zip", "https://cdn.discordapp.com/66/many.zip", 100); + t = answer_text(respond(&m)); + HAS(t, "1 log, 8 screenshots"); + HAS(t, "shot_9.png, shot_10.png, shot_11.png and 1 more in many.zip: a report keeps 8 screenshots"); + free(t); + tr_message_free(&m); + b = st_by_message(tracer.store, 9901); + m = message(9902, 990, "<@99>"); + m.reply_to = 9901; + attach(&m, "more.zip", "https://cdn.discordapp.com/66/more.zip", 100); + t = answer_text(respond(&m)); + HAS(t, "Nothing was added to report #"); + HAS(t, "more.zip: more.zip holds no log, only pictures or videos"); + HAS(t, "shot_1.png, shot_2.png in more.zip: a report keeps 8 screenshots"); + free(t); + tr_message_free(&m); + + /* a log attached whose bytes are a picture: a screenshot, never read as a log */ + serve("https://cdn.discordapp.com/66/photo.log", photo, nphoto); + serve("https://cdn.discordapp.com/66/game.log", game_log, strlen(game_log)); + m = message(9903, 991, "<@99>"); + attach(&m, "game.log", "https://cdn.discordapp.com/66/game.log", 100); + attach(&m, "photo.log", "https://cdn.discordapp.com/66/photo.log", 100); + t = answer_text(respond(&m)); + HAS(t, "1 log, 1 screenshot"); + LACKS(t, "photo.log: not a ScarletNX log"); + free(t); + tr_message_free(&m); + b = st_by_message(tracer.store, 9903); + CHECK(st_get(tracer.store, b, &r, &files, &nfiles) == 1 && nfiles == 2); + if (nfiles == 2) { + SAME(files[1].kind, "image"); + SAME(files[1].name, "photo.log"); + SAME(files[1].path, "2.png"); + } + st_report_free(&r); + st_files_free(files, nfiles); + + /* the report's three logs in: a later zip's log has no room, its screenshots do; one over 25 MiB says how much */ + m = message(9904, 991, "<@99>"); + m.reply_to = 9903; + attach(&m, "second.log", "https://cdn.discordapp.com/66/game.log", 100); + attach(&m, "third.log", "https://cdn.discordapp.com/66/game.log", 100); + free(answer_text(respond(&m))); + tr_message_free(&m); + { + size_t huge_n = TR_IMAGE_MAX + ((size_t)1 << 20); + char* huge = calloc(1, huge_n); + const char* names[] = {"scarletnx.log", "late.png", "huge.png"}; + const char* data[] = {game_log, png, huge}; + const size_t sizes[] = {0, npng, huge_n}; + memcpy(huge, "\x89PNG\r\n\x1a\n", 8); + n = zip_bytes(late, sizeof late, names, data, sizes, 3, 0); + serve("https://cdn.discordapp.com/66/late.zip", late, n); + free(huge); + } + m = message(9905, 991, "<@99>"); + m.reply_to = 9903; + attach(&m, "late.zip", "https://cdn.discordapp.com/66/late.zip", 100); + t = answer_text(respond(&m)); + HAS(t, "0 logs, 1 screenshot"); + HAS(t, "late.zip: a report keeps 3 logs"); + HAS(t, "huge.png in late.zip: it is 26.0 MiB, over the 25 MiB a screenshot may be"); + free(t); + tr_message_free(&m); + + /* a picture whose bytes are broken in the zip (its CRC fails): said, the others kept */ + { + const char* names[] = {"scarletnx.log", "bad.png", "good.png"}; + const char* data[] = {game_log, photo, png}; + const size_t sizes[] = {0, nphoto, npng}; + size_t at; + n = zip_bytes(broken, sizeof broken, names, data, sizes, 3, ZIP_STORED); + for (at = 0; at + 7 <= n && memcmp(broken + at, "a photo", 7); ++at) continue; + CHECK(at + 7 <= n); + if (at + 7 <= n) broken[at] = 'A'; /* the bytes stored, not what the zip's CRC says */ + serve("https://cdn.discordapp.com/66/broken.zip", broken, n); + } + m = message(9906, 992, "<@99>"); + attach(&m, "broken.zip", "https://cdn.discordapp.com/66/broken.zip", 100); + t = answer_text(respond(&m)); + HAS(t, "1 log, 1 screenshot"); + HAS(t, "bad.png in broken.zip: it could not be unpacked"); + free(t); + tr_message_free(&m); + (void)big; +} + /* ---- runs of edenprobe ---- */ /* ScarletNX's log of a run: its machine, then the report's lines as [game] lines. The account case's detail names a @@ -3948,39 +4257,14 @@ static int rules_only(void) { return failures != 0; } -int main(int argc, char** argv) { - char *db, *command; - if (argc == 2 && !strcmp(argv[1], "--rules")) return rules_only(); /* scripts/test-rule-mutants.sh's */ - if (argc == 2) return as_worker(argv[1]); - rei_now = clock_now; - strcpy(site, "/tmp/tracer-test-XXXXXX"); - if (!mkdtemp(site)) { - perror("mkdtemp"); - return 1; - } - db = rei_format("%s/tracer.db", site); - tracer.store = st_open(db); - tracer.root = site; - tracer.work = rei_format("%s/work", site); - CHECK(!mkdir(tracer.work, 0700)); - { - char* files = rei_format("%s/served", site); - CHECK(!mkdir(files, 0700)); - setenv("WORKER_TEST_SERVED", files, 1); - setenv("WORKER_TEST_SITE", site, 1); - free(files); - } - tracer.url = "https://reports.example"; - tracer.get = fake_get; - tracer.administers = fake_administers; - tracer.admins = NULL; - CHECK(tracer.store != NULL); - SAME(REI_AGENT, "DiscordBot (https://github.com/scarletnx/wimsy-core, 1) tracer"); +/* every test, the database's and the site's with them; self_path the test's own program, for its workers */ +static void every_test(const char* self_path) { test_message(); test_command(); test_kind_and_text(); test_images(); test_unpack(); + test_zip_images(); test_public_log(); test_channels(); test_game(); @@ -4001,15 +4285,56 @@ int main(int argc, char** argv) { test_replies(); test_mcp_grep(); test_mcp_keys(); - test_worker(argv[0]); - test_untraceable(argv[0]); + test_worker(self_path); + test_untraceable(self_path); test_issues(); test_age(); test_archive_download(); + test_zip_reports(); test_probe_reports(); test_probe_site(); test_probe_rescan(); } +} + +int main(int argc, char** argv) { + char *db, *command; + int files_only = argc == 2 && !strcmp(argv[1], "--files"); /* scripts/test-mutants.py's, as --rules */ + if (argc == 2 && !strcmp(argv[1], "--rules")) return rules_only(); + if (argc == 2 && !files_only) return as_worker(argv[1]); + rei_now = clock_now; + strcpy(site, "/tmp/tracer-test-XXXXXX"); + if (!mkdtemp(site)) { + perror("mkdtemp"); + return 1; + } + db = rei_format("%s/tracer.db", site); + tracer.store = st_open(db); + tracer.root = site; + tracer.work = rei_format("%s/work", site); + CHECK(!mkdir(tracer.work, 0700)); + { + char* files = rei_format("%s/served", site); + CHECK(!mkdir(files, 0700)); + setenv("WORKER_TEST_SERVED", files, 1); + setenv("WORKER_TEST_SITE", site, 1); + free(files); + } + tracer.url = "https://reports.example"; + tracer.get = fake_get; + tracer.administers = fake_administers; + tracer.admins = NULL; + CHECK(tracer.store != NULL); + SAME(REI_AGENT, "DiscordBot (https://github.com/scarletnx/wimsy-core, 1) tracer"); + if (files_only) { /* which files a report keeps and what of them: the attachments, a zip's, the logs' cuts */ + test_kind_and_text(); + test_images(); + test_unpack(); + test_zip_images(); + test_public_log(); + if (tracer.store) test_zip_reports(); + } else + every_test(argv[0]); st_close(tracer.store); if (getenv("TRACER_TEST_KEEP")) fprintf(stderr, "kept %s\n", site); command = rei_format(getenv("TRACER_TEST_KEEP") ? "true %s" : "rm -rf '%s'", site); From 89bea4a579a4d501a767db44189a3d900be770a5 Mon Sep 17 00:00:00 2001 From: AO55 Date: Sun, 8 Nov 2026 01:53:14 -0300 Subject: [PATCH 3/3] [tracer] A path outside a home keeps its file's name alone Report 58's log showed /mnt/// where the player keeps games: the homes' ~ covers /home and C:\Users, not a disk mounted elsewhere. A path under /mnt, /media, /run/media, /Volumes, /storage or /sdcard, or on a drive but in its \Users, \Windows and \Program Files, is now ~ and its file's name, its folders and the mount's own name gone. It is cut before the homes' ~, and the next start cuts the logs kept before (facts 7). Signed-off-by: AO55 --- docs/SECURITY.md | 7 ++- docs/TESTING.md | 8 ++- docs/TRACER.md | 15 ++++- scripts/test-mutants.py | 68 +++++++++++++++++++++- tracer/src/files.c | 112 +++++++++++++++++++++++++++++++++++-- tracer/src/files.h | 13 ++++- tracer/src/issues.c | 5 +- tracer/src/mcp.c | 3 +- tracer/src/report.c | 13 +++-- tracer/src/report.h | 12 ++-- tracer/src/site.c | 3 +- tracer/tests/test_tracer.c | 73 +++++++++++++++++++++++- 12 files changed, 297 insertions(+), 35 deletions(-) diff --git a/docs/SECURITY.md b/docs/SECURITY.md index 9d8d158..277b16d 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -81,8 +81,9 @@ searches in time linear in what it reads; nginx limits its requests by client an - ReiWimsy reads a message's text only for the numbers it names, sends GitHub only the numbers, and keeps no message, no text and no author: its state holds its replies' and cards' ids ([ReiWimsy](./REIWIMSY.md#what-it-keeps)). - Tracer keeps the sender's user id and the ids of the messages that lead to a report, for the deletion, the updates - and the hourly limit; the site and its JSON name no one. A log's home folders become `~`, its addresses `[ip]` and - `[email]`, and the crash report's dumps are left out; a picture loses its metadata and a video its place, time and - camera ([Tracer](./TRACER.md#what-a-report-keeps)). + and the hourly limit; the site and its JSON name no one. A log's home folders become `~`, and so do the folders of a + path outside them (a disk's, a drive's, Android's storage), its addresses `[ip]` and `[email]`, and the crash + report's dumps are left out; a picture loses its metadata and a video its place, time and camera + ([Tracer](./TRACER.md#what-a-report-keeps)). - AccordWimsy copies what GitHub shows publicly, each issue and comment opening with its GitHub author, day and link. - The status page keeps nothing of anyone. diff --git a/docs/TESTING.md b/docs/TESTING.md index 248b139..a7ce32a 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -50,7 +50,9 @@ temporary folder: a `.zip` (never one of its pictures, nor a Mac's fork; a name flagged UTF-8 read in the C locale, one that is no UTF-8 passed by), and the name each downloads as from the site (a log's, never the archive's); a zip's screenshots walked by name, without their folders, each read within its size; the screenshots' metadata taken out (PNG, JPEG, - WebP, GIF) and broken ones refused; an MP4's place and camera blanked; text made valid UTF-8; + WebP, GIF) and broken ones refused; an MP4's place and camera blanked; text made valid UTF-8; the paths outside a home + cut to `~` and a file's name (report 58's two lines, a drive, Android's storage, two paths on a line, a JSON string, + the mounts' own names, and what stays: the system's folders, a home, a folder named `mnt` inside a path); - the game a log names (and the older builds' titles, a garbled one, a name in another script); the crash report's dumps left out of a log as the log summary leaves them out; the games' names from the list (an update's and an add-on's ID, a report named at once, one named at the next start, a log's name first, a GBA game by its code, a @@ -106,8 +108,8 @@ temporary folder: `python3 scripts/test-mutants.py` then changes Tracer's code one way at a time in a copy of the tree, and expects its tests to fail on each: `tracer/src/rules.c` (a threshold one off, a comparison that lets one more in, a condition left out: 19 mutants, `test_tracer --rules`); what a report keeps of its files, in `files.c`, `report.c` and `issues.c` (a -zip's screenshots, a picture never read as a log, the limits said with their values: 17 mutants, `test_tracer ---files`); and the worker's locale for a zip's names, made before it shuts itself in (1 mutant, +zip's screenshots, a picture never read as a log, the paths outside a home, the limits said with their values: 30 +mutants, `test_tracer --files`); and the worker's locale for a zip's names, made before it shuts itself in (1 mutant, the whole suite). A mutant they pass, or one whose text its file no longer has once, fails it. About 30 s. `make -C tracer bench [RUNS=1000] [FOLDER=/tmp/tracer-bench]` (`tracer/tests/bench_probe.c`, built by `make test`, diff --git a/docs/TRACER.md b/docs/TRACER.md index 1893daa..b33b9ed 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -62,6 +62,14 @@ for it). The worker's answer is checked before any of its files moves from the w file that is no picture or video; never one of its pictures, nor a Mac's `__MACOSX/` fork. A zip's names are read as UTF-8 whatever the worker's locale (ScarletNX's Share Log flags each name so), in a locale it makes before it shuts itself in; an entry whose name it cannot read is passed by, and the walk goes on. +- Each absolute path outside a home folder in a log is written as `~` and its file's name, as where a player keeps + games says how they arrange their disks, and a disk's label may be theirs: a path under `/mnt`, `/media`, + `/run/media`, `/Volumes` (macOS), `/storage` or `/sdcard` (Android), or on a drive (`D:\`, `D:/`, WSL's `/mnt/d/`) but + in its `\Users` (a home, written as one), `\Windows` and `\Program Files` (the system's and the programs', which name + no one). `/mnt/Disk/Games/Some Game.nsp (9 MB mapped)` becomes `~/Some Game.nsp (9 MB mapped)`; its folders go, and so + does the mount's own name (a disk's label, an account's under `/media`), as `/media/someone` becomes `~`. The last + name stays when it is a file's (a dot, then a letter or a digit); one that is no file's goes with the words after it + on the line, which nothing tells from it, as an account's name does. - Its screenshots (PNG, JPEG, WebP, GIF or PPM, read from their bytes; 8 at most, 25 MiB each), attached or in a `.zip` beside its log (each entry named `.png`, `.jpg`, `.jpeg`, `.webp`, `.gif` or `.ppm`, kept under its file's name without the zip's folders; a Mac's `__MACOSX/` forks are none), lose their metadata: EXIF and its place and camera, @@ -169,7 +177,7 @@ When the log summary or the list of names changes (`scripts/sync-logscan.sh`, `s report keeps of its logs (`TR_FACTS`), the next start summarizes each kept log again, draws each report's facts again from its first log, files a report whose first log now names another game under that game, names one its logs don't name from the list, makes a report whose first log holds a run of edenprobe the run's, and takes out of each kept log -what a run's lines would say of the player. A report keeps no zip, only its log and +what a run's lines would say of the player and the paths outside a home. A report keeps no zip, only its log and screenshots: a zip's screenshots sent before Tracer read them are not found again, and are added by a reply with them. ## Commands @@ -190,8 +198,9 @@ A report becomes a GitHub issue once a server's administrator approves it: with administrator of the server it was sent in (or one of `TRACER_ADMINS`) reacts to one of its messages (the one that sent it, an update, Tracer's answer) with the approval's emoji, `TRACER_ISSUES_EMOJI`, the check mark by default. Tracer opens the issue in that repository with what the site shows of the report: its facts and its first log's summary (home -folders as `~`, addresses as `[ip]` and `[email]`, no dumps), each of a log's or a player's words in a code block, where -GitHub links no `@name` and no `#number`, the report's page, and its screenshots, each the site's picture 320 pixels wide linked to it and named by its number in the report (a file's +folders and the folders of paths outside them as `~`, addresses as `[ip]` and `[email]`, no dumps), each of a log's or +a player's words in a code block, where GitHub links no `@name` and no `#number`, the report's page, and its +screenshots, each the site's picture 320 pixels wide linked to it and named by its number in the report (a file's name is a player's words). GitHub's API takes no file for an issue: its image proxy fetches each picture from the site, so the site must answer it. The issue's number goes into the database, onto the report's page and its JSON, and into a short reply on Discord. A report is filed once: a second approval opens no diff --git a/scripts/test-mutants.py b/scripts/test-mutants.py index c03ebde..4a71ce0 100755 --- a/scripts/test-mutants.py +++ b/scripts/test-mutants.py @@ -5,7 +5,8 @@ the runs of edenprobe (tracer/src/rules.c, tests run as test_tracer --rules: a threshold one off, a comparison that lets one more in, a condition left out), and which files a report keeps and what of them (tracer/src/files.c, report.c and issues.c, tests run as test_tracer --files: a zip's screenshots, a picture never read as a log, the -limits said with their values; the worker's locale for a zip's names, by the whole suite). A mutant the tests pass is a rule nothing holds. Each runs in a copy of the tree in a temporary folder; the +paths outside a home cut, the limits said with their values; the worker's locale for a zip's names, by the whole +suite). A mutant the tests pass is a rule nothing holds. Each runs in a copy of the tree in a temporary folder; the checkout is never written. python3 scripts/test-mutants.py [--root DIR] [--cc CC] @@ -160,6 +161,58 @@ ' if ((size_t)got > max - out->len) {\n buf_free(out);\n return 1;', ' if ((size_t)got > max - out->len + 1) {\n buf_free(out);\n return 1;', ), + ( + 'no path outside a home is cut', + 'files.c', + '(len = outside_home(s + i, n - i, &keep))) {', + '(len = 0 * outside_home(s + i, n - i, &keep))) {', + ), + ('/mnt is no root', 'files.c', '{"/mnt/", 1}', '{"/nomnt/", 1}'), + ( + "the first byte's look passes a drive by", + 'files.c', + "if ((s[i] == '/' || (i + 1 < n && s[i + 1] == ':' && letter(s[i]))) && path_start(s, i) &&", + "if ((s[i] == '/') && path_start(s, i) &&", + ), + ( + "a mount's own name stays", + 'files.c', + 'if (folders >= names && file_name(s + start, i - start)) {', + 'if (file_name(s + start, i - start)) {', + ), + ( + "a folder's name stays as a file's", + 'files.c', + 'if (folders >= names && file_name(s + start, i - start)) {', + 'if (folders >= names) {', + ), + ("a drive's Users folder is cut", 'files.c', '{"users", "windows", ', '{"windows", '), + ('Windows is cut', 'files.c', '{"users", "windows", ', '{"users", '), + ("WSL's drive is a mount", 'files.c', 'return left_on_drive(s + 7, n - 7) ? 0 : 7;', 'return 0;'), + ( + 'a folder named mnt inside a path is a root', + 'files.c', + 'return !(letter(c) || digit(c) || strchr("._-~/\\\\", c));', + 'return 1;', + ), + ( + 'a blank before another path ends no name', + 'files.c', + "if (s[i] == ' ' && path_next(s + i + 1, n - i - 1)) break;", + 'continue;', + ), + ( + "a JSON string's doubled backslash is halved", + 'files.c', + 'while (keep < len && sep > 0 && path_sep(s[i + sep - 1], 1)) --sep;', + 'if (keep < len) sep = keep - 1;', + ), + ( + "the line's blanks go with a name that goes", + 'files.c', + "while (i > start && s[i - 1] == ' ') --i;", + '', + ), ( "a zip's screenshots are not taken", 'report.c', @@ -192,6 +245,19 @@ 'return rei_format("it is %.1f MiB, over the %zu MiB a %s may be", bytes / (1 << 20), max_of(kind) >> 20,', 'return rei_format("over %.0f%zu MiB%s", bytes * 0, max_of(kind) >> 20,', ), + ( + "the homes' ~ comes before the paths' cut", + 'report.c', + ' shown = tr_public_log(text.text, text.len, &n); ' + "/* before the homes' ~, which would keep /media/'s folders */\n" + ' buf_free(&text);\n' + ' tilded = snx_logscan_tilde(shown, n, &n);\n' + ' free(shown);', + ' shown = snx_logscan_tilde(text.text, text.len, &n);\n' + ' buf_free(&text);\n' + ' tilded = tr_public_log(shown, n, &n);\n' + ' free(shown);', + ), ( 'the issue has no screenshots', 'issues.c', diff --git a/tracer/src/files.c b/tracer/src/files.c index a6c140b..918c154 100644 --- a/tracer/src/files.c +++ b/tracer/src/files.c @@ -660,14 +660,118 @@ static size_t email(const char* s, size_t n, size_t at, size_t* from) { *from = a; return z - a; } -/* a line of the log as the site shows it, into b: each IPv4 address but the loopback's, 0.0.0.0 and a mask (255.) as - [ip], each e-mail address as [email]. A player's address and the other players' on a network game are theirs */ +/* ---- paths outside a home: where a player keeps games and folders says how they arrange their disks, and a disk's + label or a mount's name may be theirs ---- */ + +/* a byte no path in a log runs past: a control (a line's end among them), or one no Windows name holds ('"', '<', + '>', '|', '*', '?'); a quote ends a path a JSON string holds */ +static int path_end(char c) { return (unsigned char)c < 0x20 || c == 0x7f || (c && strchr("\"<>|*?", c)); } +static int path_sep(char c, int both) { return c == '/' || (both && c == '\\'); } +/* a drive's root at s, D:\ or D:/: 3, else 0 */ +static size_t drive_root(const char* s, size_t n) { + return n >= 3 && letter(s[0]) && s[1] == ':' && (s[2] == '\\' || s[2] == '/') ? 3 : 0; +} +/* a drive's folder at s that the cut leaves, in any case: Users (a home: snx_logscan_tilde writes its own ~), Windows + and Program Files, with or without (x86) (the system's and the programs', which name no one) */ +static int left_on_drive(const char* s, size_t n) { + static const char* const left[] = {"users", "windows", "program files", "program files (x86)"}; + size_t k, len; + for (k = 0; k < sizeof left / sizeof *left; ++k) { + len = strlen(left[k]); + if (n >= len && !strncasecmp(s, left[k], len) && (n == len || s[len] == '\\' || s[len] == '/')) return 1; + } + return 0; +} +/* the root of an absolute path outside a home at s: its length, *names how many names after it are the mount's own (a + disk's label, an account's under /media), which never stay, and *both whether \ parts its names too (a drive's); + 0 for none, and for a drive's folder the cut leaves */ +static size_t path_root(const char* s, size_t n, int* names, int* both) { + static const struct { + const char* root; + int names; + } mounts[] = {{"/run/media/", 1}, {"/media/", 1}, {"/mnt/", 1}, + {"/Volumes/", 1}, {"/storage/", 1}, {"/sdcard/", 0}}; + size_t k, len; + *names = 0; + *both = 0; + if (n >= 7 && !strncmp(s, "/mnt/", 5) && letter(s[5]) && s[6] == '/') /* WSL's drive */ + return left_on_drive(s + 7, n - 7) ? 0 : 7; + if (drive_root(s, n)) { + *both = 1; + return left_on_drive(s + 3, n - 3) ? 0 : 3; + } + for (k = 0; k < sizeof mounts / sizeof *mounts; ++k) { + len = strlen(mounts[k].root); + if (n >= len && !strncmp(s, mounts[k].root, len)) { + *names = mounts[k].names; + return len; + } + } + return 0; +} +/* a file's name, not a folder's or a disk's: a dot, then a letter or a digit, after its first byte */ +static int file_name(const char* s, size_t n) { + size_t i; + for (i = 1; i + 1 < n; ++i) + if (s[i] == '.' && (letter(s[i + 1]) || digit(s[i + 1]))) return 1; + return 0; +} +/* whether a path may start at s + i: at the line's start, after file://, or after a byte no name ends with (a blank, + a quote, a bracket, '='), so that a folder named mnt in the middle of a path is no root */ +static int path_start(const char* s, size_t i) { + char c = i ? s[i - 1] : ' '; + if (i >= 7 && !memcmp(s + i - 7, "file://", 7)) return 1; + return !(letter(c) || digit(c) || strchr("._-~/\\", c)); +} +/* whether another path starts after a blank at s, a quote or a bracket before it or not: a separator, a drive or + file:// */ +static int path_next(const char* s, size_t n) { + if (n && (s[0] == '\'' || s[0] == '(' || s[0] == '[')) ++s, --n; + return n && (path_sep(s[0], 1) || drive_root(s, n) || (n >= 7 && !memcmp(s, "file://", 7))); +} +/* the length of the absolute path outside a home at s, *keep where its last name starts when that name stays (a + file's, past the mount's own names), else that length. A name runs to a separator, to a byte no path holds or the + line's end, or to a blank before another path: a name no separator follows cannot be told from the words after it, + which go with it when it goes (as snx_logscan_tilde takes an account's name). 0 for no such path, or a root and no + name */ +static size_t outside_home(const char* s, size_t n, size_t* keep) { + int names, both, folders = 0; + size_t i = path_root(s, n, &names, &both), start; + if (!i || i >= n || path_end(s[i]) || s[i] == ' ') return 0; + for (;;) { + for (start = i; i < n && !path_end(s[i]) && !path_sep(s[i], both); ++i) + if (s[i] == ' ' && path_next(s + i + 1, n - i - 1)) break; + if (i == n || !path_sep(s[i], both)) break; + folders += i > start; + ++i; + } + if (folders >= names && file_name(s + start, i - start)) { + *keep = start; + return i; + } + while (i > start && s[i - 1] == ' ') --i; /* the line's blanks after a name that goes */ + *keep = i; + return i; +} + +/* a line of the log as the site shows it, into b: each absolute path outside a home as ~ and its file's name, each + IPv4 address but the loopback's, 0.0.0.0 and a mask (255.) as [ip], each e-mail address as [email]. A player's + address and the other players' on a network game are theirs */ static void scrubbed(Buf* b, const char* s, size_t n) { size_t i = 0, done = 0; while (i < n) { - size_t len, from; + size_t len, from, keep; unsigned first = 0; - if (digit(s[i]) && (!i || (!digit(s[i - 1]) && s[i - 1] != '.')) && (len = ipv4(s + i, n - i, &first))) { + /* a root is a / or a drive's letter and colon: the rest of the bytes cost one look */ + if ((s[i] == '/' || (i + 1 < n && s[i + 1] == ':' && letter(s[i]))) && path_start(s, i) && + (len = outside_home(s + i, n - i, &keep))) { + size_t sep = keep; /* the separators before the file's name, both of a JSON string's doubled one */ + buf_addn(b, s + done, i - done); + buf_add(b, "~"); + while (keep < len && sep > 0 && path_sep(s[i + sep - 1], 1)) --sep; + if (keep < len) buf_addn(b, s + i + sep, len - sep); + done = i = i + len; + } else if (digit(s[i]) && (!i || (!digit(s[i - 1]) && s[i - 1] != '.')) && (len = ipv4(s + i, n - i, &first))) { if (first != 127 && first != 255 && (first || strncmp(s + i, "0.0.0.0", len))) { buf_addn(b, s + done, i - done); buf_add(b, "[ip]"); diff --git a/tracer/src/files.h b/tracer/src/files.h index 8b973c6..b6cbb23 100644 --- a/tracer/src/files.h +++ b/tracer/src/files.h @@ -2,7 +2,8 @@ Copyright 2026 the ScarletNX contributors */ /* The bytes of the files a report keeps: which attachment is a log and which a screenshot, a log unpacked from its .gz or .zip and the screenshots beside it in the .zip, a screenshot's kind read from its bytes and its metadata (camera, - place, time, text) taken out, and text made valid UTF-8 for the site */ + place, time, text) taken out, a log as the site shows it (no dumps, addresses or paths of the player's), and text + made valid UTF-8 for the site */ #ifndef TR_FILES_H #define TR_FILES_H #include "tracer.h" @@ -78,7 +79,13 @@ size_t tr_stamp(const char* s, size_t n); char* tr_utf8(const char* text, size_t n); /* a log as the site shows it: without the crash report's lines that hold the game's bytes or its registers (its code - and memory dumps), which the log summary keeps out of its own (logscan.c's dump()), and with each IPv4 address but - the loopback's as [ip] and each e-mail address as [email]. Owned, its length in *size */ + and memory dumps), which the log summary keeps out of its own (logscan.c's dump()), with each IPv4 address but the + loopback's as [ip] and each e-mail address as [email], and each absolute path outside a home folder as ~ and its + file's name. Such a path is under /mnt, /media, /run/media, /Volumes (macOS), /storage or /sdcard (Android), or on a + drive (D:\, D:/, WSL's /mnt/d/) but in its \Users (a home: snx_logscan_tilde's), \Windows or \Program Files (the + system's, which name no one); its folders go, and with them the mount's own name (a disk's label, an account's), and + its last name stays when it is a file's (a dot, then a letter or a digit, after its first byte): + "/mnt/Disk/Games/Some Game.nsp (9 MB)" as "~/Some Game.nsp (9 MB)", "/media/someone" as "~". It runs before + snx_logscan_tilde, which would make /media/ a home and keep the folders under it. Owned, its length in *size */ char* tr_public_log(const char* text, size_t n, size_t* size); #endif diff --git a/tracer/src/issues.c b/tracer/src/issues.c index 4402a6d..2b252af 100644 --- a/tracer/src/issues.c +++ b/tracer/src/issues.c @@ -194,8 +194,9 @@ char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const ch buf_add(&b, "text\n"); buf_add(&b, facts.text ? facts.text : ""); for (i = 0; i < (int)fence; ++i) buf_add(&b, "`"); - buf_add(&b, "\n\nThe log's home folders are written as ~ and its addresses as [ip] and [email]; the crash report's " - "dumps of the game's bytes are not in it.\n"); + buf_add(&b, + "\n\nThe log's home folders, and the folders of a path outside them, are written as ~ and its addresses " + "as [ip] and [email]; the crash report's dumps of the game's bytes are not in it.\n"); shots(&b, r->id, files, nfiles, url); buf_free(&facts); cJSON_Delete(s); diff --git a/tracer/src/mcp.c b/tracer/src/mcp.c index 944206f..467e6ab 100644 --- a/tracer/src/mcp.c +++ b/tracer/src/mcp.c @@ -21,7 +21,8 @@ static const char INSTRUCTIONS[] = "get_screenshot shows a report's screenshot. Runs of edenprobe (its cases on each emulator, driver and system) are " "reports of their own: probe_matrix lists the cases by machine, probe_case gives a case's results and failures, " "ban_candidates what the runs say together (drivers to ban, ScarletNX's own failures, regressions). " - "Home folders in the logs are ~. A Switch log that failed has a symbolize " + "Home folders in the logs are ~, and so are the folders of a path outside them (its file's name stays). A Switch " + "log that failed has a symbolize " "object in get_report: its title ID, game version and game addresses. ScarletNX's own MCP server (scarletnx " "--mcp), where a copy of the game is, names them: its find_game with that title_id, the game whose version is " "game_version, then its symbolize (or disassemble) with that game's path and the addresses. This server has no " diff --git a/tracer/src/report.c b/tracer/src/report.c index 831bd23..6031396 100644 --- a/tracer/src/report.c +++ b/tracer/src/report.c @@ -240,8 +240,9 @@ static cJSON* help(void) { "A run of edenprobe is a report of its own, apart from the games: ScarletNX's log of the run (alone, or in " "the Share Log zip), Eden's log of it, or its report.jsonl (the console's, as it names no machine). The " "detail of its service, net and pad cases is left out, as it can name you.\n\n" - "Home folders in a log are shown as ~, and screenshots lose their metadata. The site does not show " - "who sent a report.\n\n" + "Home folders in a log are shown as ~, and so are the folders of a path outside them (a disk's, a " + "drive's): its file's name stays. Screenshots lose their metadata. The site does not show who sent a " + "report.\n\n" "To add logs, screenshots or a note to a report, reply to it (or to my answer) and mention me, or write " "`@Tracer add 12` with them. For a log someone sent without mentioning me, reply to their message and " "mention me: I make a report of it.\n\n" @@ -471,16 +472,16 @@ static void take_log(Taken* k, int dirfd, const TrAttachment* a, Buf* got) { buf_free(&text); return; } - tilded = snx_logscan_tilde(text.text, text.len, &n); + shown = tr_public_log(text.text, text.len, &n); /* before the homes' ~, which would keep /media/'s folders */ buf_free(&text); + tilded = snx_logscan_tilde(shown, n, &n); + free(shown); if (!tilded) { skip(k, a->name, "out of memory"); return; } - shown = tr_public_log(tilded, n, &n); + cut = probe_cut(tilded, n, &n, &cases, ¬es); /* what edenprobe's lines would say of the player, out */ free(tilded); - cut = probe_cut(shown, n, &n, &cases, ¬es); /* what edenprobe's lines would say of the player, out */ - free(shown); shown = cut; summary = summary_of(shown, n); parsed = summary ? cJSON_Parse(summary) : NULL; diff --git a/tracer/src/report.h b/tracer/src/report.h index 37de27f..0a4f0be 100644 --- a/tracer/src/report.h +++ b/tracer/src/report.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: GPL-3.0-or-later Copyright 2026 the ScarletNX contributors */ /* What Tracer does with a message that mentions it: a report made of its logs and screenshots (downloaded, a .zip's - screenshots beside its log, the logs' home folders shown as ~, their summaries made, the screenshots' metadata taken - out), kept in the database and the site's folder; "delete N" and "help" answered. Each answer is an embed for a - reply */ + screenshots beside its log, the logs' home folders and the folders of paths outside them shown as ~, their summaries + made, the screenshots' metadata taken out), kept in the database and the site's folder; "delete N" and "help" + answered. Each answer is an embed for a reply */ #ifndef TR_REPORT_H #define TR_REPORT_H #include "age.h" @@ -59,8 +59,8 @@ struct Tracer { }; /* m's attachments downloaded through t's get and read: the logs unpacked (a .zip's screenshots taken beside its log), - their home folders as ~, their dumps and addresses left out and summarized, the screenshots' metadata taken out; - each kept one written into k->dir, each other named in k->skipped */ + their home folders and the folders of paths outside them as ~, their dumps and addresses left out and summarized, + the screenshots' metadata taken out; each kept one written into k->dir, each other named in k->skipped */ void tr_take(Tracer* t, Taken* k, const TrMessage* m); /* tr_take's two halves, which a worker splits by shutting itself in its folder between them (wk_shut_in): m's attachments downloaded through t's get into the folder dirfd (k->dir), attachment i as "in.", or why[i] (owned) @@ -81,7 +81,7 @@ int tr_game(const cJSON* summary, const char* note, char** key, char** title, ch commands" (shaders by the shaders, the rest by the different ones); owned, NULL for nothing */ char* tr_missed(const cJSON* summary); /* what a report keeps of its logs, as a version: a new one summarizes the kept reports again (tr_rescan) */ -#define TR_FACTS "facts 6" +#define TR_FACTS "facts 7" /* the reply to m, a message that mentions the bot: an embed (owned), or NULL for a message already handled (the gateway sends a message again after a resume). *report is the report it made or updated, 0 for none: the reply, diff --git a/tracer/src/site.c b/tracer/src/site.c index 15ee543..029b0a7 100644 --- a/tracer/src/site.c +++ b/tracer/src/site.c @@ -94,7 +94,8 @@ static void head(Buf* b, const char* root, const char* title, const char* descri } static void foot(Buf* b) { buf_add(b, "\n
Reports that players sent to Tracer on Discord, with logs of " - "ScarletNX. Home folders in the logs are shown as ~.
\n" + "ScarletNX. Home folders in the logs, and the folders of a path outside " + "them, are shown as ~.\n" "\n\n"); } /* the controls site.js reads: a search, and a choice of each key's values (filled in from the rows) */ diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index 0d5c57e..e1dbf38 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -780,6 +780,58 @@ static void test_public_log(void) { CHECK(tilded && n == strlen(tilded)); free(tilded); } + { /* an absolute path outside a home: ~ and its file's name. Report 58's two lines first (a Linux player's games on a + disk under /mnt), then the shapes the players' logs show: a Windows drive, Android's shared storage, two paths + on a line, a JSON string's doubled backslash, and the mounts' own names, which never stay */ + static const char paths[] = + "[ 0,07] log: written to /mnt/Files/Games/NSW/.local/state/scarletnx/recompiled/0100AAAABBBB0000/" + "0100AAAABBBB0000.log\n" + "[ 0,08] fs: ExeFS and RomFS read from the dump /mnt/Files/Games/NSW/ROMS/Some Game/Some Game " + "[0100AAAABBBB0000] [v1376256] (1G+1U).nsp (11509,5 MB mapped)\n" + "dump C:\\ScarletNX-windows-x86_64\\Switch\\Some Game [0100aaaabbbb0000][v0][Base].nsp (1005.2 MB mapped)\n" + "shaders from F:\\Jogos\\ScarletNX\\0100AAAABBBB0000\\shader_cache\\0100AAAABBBB0000.vkshaders in 73 ms\n" + "-r /storage/emulated/0/Download/Switch/Some Game.nsp --data /data/data/org.scarletnx/files/.scarletnx/\n" + "on /run/media/someone/Disk/x.png, /Volumes/Some Disk/Games/x.nsp and D:/Games/x.xci\n" + "WSL: /mnt/c/Games/x.nsp file:///mnt/d/x.png '/sdcard/x.nsp'\n" + "mounts: /mnt/Arquivos, /media/john.doe and /Volumes/John's Disk \n" + "{\"path\":\"E:\\\\Games\\\\x.nsp\",\"other\":\"E:\\\\Saves\"}\n" + "stay: C:\\Windows\\System32\\vulkan-1.dll, C:\\Program Files (x86)\\Steam\\x.dll, /dev/input/event16\n" + "stay: /home/someone/mnt/x, https://example.org/mnt/x.png, /srv/mnt/x, under /mnt/ and D:\\\n" + "stay: C:\\Users\\Some One\\x.sav and /mnt/c/users/someone/x.sav, for the homes' ~"; + char* tilded; + shown = tr_public_log(paths, sizeof paths - 1, &n); + SAME(shown, + "[ 0,07] log: written to ~/0100AAAABBBB0000.log\n" + "[ 0,08] fs: ExeFS and RomFS read from the dump ~/Some Game [0100AAAABBBB0000] [v1376256] " + "(1G+1U).nsp (11509,5 MB mapped)\n" + "dump ~\\Some Game [0100aaaabbbb0000][v0][Base].nsp (1005.2 MB mapped)\n" + "shaders from ~\\0100AAAABBBB0000.vkshaders in 73 ms\n" + "-r ~/Some Game.nsp --data /data/data/org.scarletnx/files/.scarletnx/\n" + "on ~/x.png, ~/x.nsp and ~/x.xci\n" + "WSL: ~/x.nsp file://~/x.png '~/x.nsp'\n" + "mounts: ~ ~ ~ \n" + "{\"path\":\"~\\\\x.nsp\",\"other\":\"~\"}\n" + "stay: C:\\Windows\\System32\\vulkan-1.dll, C:\\Program Files (x86)\\Steam\\x.dll, /dev/input/event16\n" + "stay: /home/someone/mnt/x, https://example.org/mnt/x.png, /srv/mnt/x, under /mnt/ and D:\\\n" + "stay: C:\\Users\\Some One\\x.sav and /mnt/c/users/someone/x.sav, for the homes' ~"); + CHECK(n == strlen(shown)); + LACKS(shown, "Files/Games"); + LACKS(shown, "john"); + /* then the homes' ~, as take_log does: a desktop's /media/ mount loses its folders too, which the homes' + ~ alone would keep */ + tilded = snx_logscan_tilde(shown, n, &n); + HAS(tilded, "stay: ~\\x.sav and ~/x.sav, for the homes' ~"); + free(tilded); + free(shown); + shown = tr_public_log("at /media/someone/Disk/Games/x.nsp\n", 36, &n); + tilded = snx_logscan_tilde(shown, n, &n); + SAME(tilded, "at ~/x.nsp\n"); + free(tilded); + free(shown); + tilded = snx_logscan_tilde("at /media/someone/Disk/Games/x.nsp\n", 36, &n); + SAME(tilded, "at ~/Disk/Games/x.nsp\n"); + free(tilded); + } /* each prefix the log summary's dump() leaves out is left out here: a prefix added there fails this until it is */ source = read_file("third_party/logscan/common/utilities/logscan.c", NULL); where = source ? strstr(source, "static int dump(Span line)") : NULL; @@ -1532,6 +1584,15 @@ static void test_rescan(void) { st_report_free(&r); st_files_free(files, nfiles); free(dumped); + /* and one kept before paths outside a home were cut (report 58's): its folders go at the next start */ + dumped = rei_format("%s[ 3.00] fs: read from the dump /mnt/Files/Games/Some Game.nsp (9 MB)\n", text); + CHECK(!site_write(site, "r/2/1.log", dumped, strlen(dumped))); + CHECK(tr_rescan(&tracer, "f") == 12); + free(text); + text = read_file(path, &n); + HAS(text, "fs: read from the dump ~/Some Game.nsp (9 MB)\n"); + LACKS(text, "Files/Games"); + free(dumped); free(text); free(path); } @@ -3039,7 +3100,10 @@ static void test_zip_reports(void) { int nfiles, i; long a, b; char *t, *p, *rel; - snprintf(game_log, sizeof game_log, "%s", LOG); + snprintf(game_log, sizeof game_log, "%s%s", LOG, + "[ 0,08] fs: ExeFS and RomFS read from the dump /mnt/Files/Games/NSW/ROMS/Some Game/Some Game " + "[0100AAAABBBB0000] [v1376256] (1G+1U).nsp (11509,5 MB mapped)\n" + "[ 0,09] fs: saves in /media/someone/Disk/Saves/x.sav\n"); { /* the Share Log zip: the game's log first, the launcher's, five pictures at its root (one a PPM in a folder, one no picture at all), a Mac's fork, the summary */ const char* names[] = {"games/Some G\xc3\xa1me [0100AAAABBBB0000]/2026-11-07_21-45-11.log", @@ -3074,13 +3138,17 @@ static void test_zip_reports(void) { SAME(files[2].name, "screenshot_20261107_214311.png"); SAME(files[3].name, "screenshot_20261107_214321.ppm"); SAME(files[3].path, "4.png"); + LACKS(files[0].summary, "Files/Games"); } st_report_free(&r); st_files_free(files, nfiles); rel = rei_format("r/%ld/1.log", a); p = page(rel); HAS(p, "ScarletNX - Some Game"); /* the game's log, no picture */ - LACKS(p, "\x89PNG"); + HAS(p, "read from the dump ~/Some Game [0100AAAABBBB0000] [v1376256] (1G+1U).nsp (11509,5 MB mapped)"); + LACKS(p, "Files/Games"); + HAS(p, "saves in ~/x.sav\n"); /* cut before the homes' ~, which keeps the folders under /media/ */ + LACKS(p, "someone"); free(p); free(rel); rel = rei_format("%s/r/%ld/2.png", site, a); @@ -3127,6 +3195,7 @@ static void test_zip_reports(void) { HAS(gh_body, p); free(p); LACKS(gh_body, "screenshot_20261107"); /* a file's name is a player's words: outside the code block, none */ + LACKS(gh_body, "Files/Games"); } /* twelve pictures: eight kept, the rest named in one line with the room; an update with two more, no room left */