Skip to content

SafeFile: demote oversized-string assertion to debug log (#246) - #617

Merged
mrjimenez merged 1 commit into
amule-project:masterfrom
got3nks:fix/safefile-writestring-assert
May 15, 2026
Merged

SafeFile: demote oversized-string assertion to debug log (#246)#617
mrjimenez merged 1 commit into
amule-project:masterfrom
got3nks:fix/safefile-writestring-assert

Conversation

@got3nks

@got3nks got3nks commented May 15, 2026

Copy link
Copy Markdown
Contributor

Summary

CFileDataIO::WriteStringCore wxFAIL_MSGs when asked to serialise a string larger than 0xFFFF bytes with a uint16 length prefix. Per the surrounding code's own comment, the trigger is peer-supplied data that expands past 16 bits after ISO8859-1 → UTF-8 conversion — exactly the "external data should not trigger an assertion" pattern that PR #613 addressed for OP_IDCHANGE. Crashes debug builds for the two reporters in #246 (drzraf 2021 writing Kad contacts; fekir 2024 startup/shutdown event loop).

Why it's safe to demote

The immediately-following code already truncates the value and adjusts the BOM-adjusted sLength before writing — so release builds silently absorb the oversized input without on-disk corruption:

if (real_length > 0xFFFF) {
    wxFAIL_MSG("String is too long to be saved");   // <- aborts debug, no-op release

    real_length = std::min<uint32>(real_length, 0xFFFF);  // <- already truncates
    if (eEncode == utf8strOptBOM) {
        sLength = real_length - 3;
    } else {
        sLength = real_length;
    }
}

The wxFAIL_MSG therefore guards no behaviour — release builds run the truncation path identically without it.

Change

Replace wxFAIL_MSG with AddDebugLogLineN(logCFile, ...) that records the original byte count for diagnosis. The truncation path is unchanged; on-disk format is unchanged. Same shape as #613.

// after
if (real_length > 0xFFFF) {
    AddDebugLogLineN(logCFile,
        CFormat(wxT("WriteStringCore: oversized string (%u bytes) truncated to 0xFFFF"))
            % real_length);
    real_length = std::min<uint32>(real_length, 0xFFFF);
    ...
}

Closes the assertion-symptom side of #246. The unrelated epoll_ctl symptom from the original 2021 report is likely incidentally fixed by 86c4769d8 (libcurl-based HTTPDownload replacing the old wxFDIODispatcher path) but needs a fresh log to confirm; tracked separately.

…ct#246)

CFileDataIO::WriteStringCore wxFAIL_MSGs when asked to serialise a
string larger than 0xFFFF bytes with a uint16 length prefix. The
intent (per the surrounding comment) is to flag peer-supplied data
that expands past 16 bits after ISO8859-1 -> UTF-8 conversion --
exactly the "external data should not trigger an assertion" pattern
that PR amule-project#613 addressed for OP_IDCHANGE.

The immediately-following code already does the right thing: it
truncates real_length to 0xFFFF and adjusts sLength accordingly, so
release builds silently absorb the oversized input. Debug builds,
however, abort on what is harmless input -- crashing amuled on every
periodic save where any single Kad contact field has been poisoned
(see amule-project#246, drzraf 2021 and fekir 2024).

Replace wxFAIL_MSG with AddDebugLogLineN(logCFile, ...) that records
the original byte count for diagnosis without aborting. The
truncation path is unchanged; on-disk format is unchanged.

Same shape as PR amule-project#613 / issue amule-project#610.

Reported by drzraf and fekir.
@mrjimenez
mrjimenez merged commit 946f8d1 into amule-project:master May 15, 2026
12 checks passed
@got3nks
got3nks deleted the fix/safefile-writestring-assert branch May 15, 2026 18:19
got3nks added a commit to got3nks/amule that referenced this pull request Jul 29, 2026
Closes amule-project#617.

Downloads: a "Total queue size: X" field, right-aligned in the File
sources row, summing the files currently visible (selected category +
text filter). Kept live the same way as the file count -- reset in bulk
by RebuildVisibleList(), adjusted by GetFileSize() as ShowFile() adds or
removes a row -- so there is no per-tick cost.

Shared: the combined size of the visible shared files, shown as "Total
size of Shared Files: X" (reusing the existing string) in the statistics
box, in place of the "Percent of total files" label -- which was
misleading, since the gauges beside it show a session/all-time ratio per
selected file, not a percentage of files. The session/all-time gauges
stay.

Both auto-scale units via CastItoXBytes and work in amuleGUI too: file
sizes are already EC-streamed, so no core/protocol change is needed. The
"Total queue size: %s" string is new; the shared label reuses an existing
one. Catalogs regenerated.
ngosang pushed a commit to ngosang/amule that referenced this pull request Jul 29, 2026
…project#689)

Closes amule-project#617.

Downloads: a "Total queue size: X" field, right-aligned in the File
sources row, summing the files currently visible (selected category +
text filter). Kept live the same way as the file count -- reset in bulk
by RebuildVisibleList(), adjusted by GetFileSize() as ShowFile() adds or
removes a row -- so there is no per-tick cost.

Shared: the combined size of the visible shared files, shown as "Total
size of Shared Files: X" (reusing the existing string) in the statistics
box, in place of the "Percent of total files" label -- which was
misleading, since the gauges beside it show a session/all-time ratio per
selected file, not a percentage of files. The session/all-time gauges
stay.

Both auto-scale units via CastItoXBytes and work in amuleGUI too: file
sizes are already EC-streamed, so no core/protocol change is needed. The
"Total queue size: %s" string is new; the shared label reuses an existing
one. Catalogs regenerated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants