From e198aff5bde2c64aefc8a27f836dc87ab720cde8 Mon Sep 17 00:00:00 2001 From: Warren Paul Date: Mon, 19 Oct 2026 16:21:09 -0500 Subject: [PATCH] api_dump: Escape strings in JSON output dump_char wrote string values into the JSON dump as-is, wrapped in quotes. A string containing a line break, quote, backslash or other control character made the .apidump file invalid JSON, and readers stopped parsing at that point, losing every frame after it. Vulkan Samples "subpasses" triggers this: it names a render pass "RP with 2 subpasses:" followed by line breaks. Add dump_json_string_w, which escapes '"', '\\' and all control characters as JSON requires (\n, \r, \t, \b, \f, and \u00XX for the rest), and use it in dump_char's JSON path. Text that needs no escaping is still written in one piece through ApiDumpFastWriter. Every string the layer dumps goes through dump_char: all 58 generated char*, char[N] and char* array fields and parameters, including object names, debug labels, instance info, layer and extension names, and device and driver properties. The generator does the same for every char type, so the fix holds when the code is regenerated. Other JSON values (function names, type names, numbers, flags) are fixed text or numbers. Text and HTML output are unchanged. [Co-Developed using AI] Claude-opus-5.5 --- layersvt/api_dump.h | 50 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/layersvt/api_dump.h b/layersvt/api_dump.h index 425b34983a..9071e61edf 100644 --- a/layersvt/api_dump.h +++ b/layersvt/api_dump.h @@ -1821,6 +1821,53 @@ void dump_json_value_w(ApiDumpFastWriter &writer, const ApiDumpSettings &setting writer << '"'; } +// A string as a Json value: quoted, with the quote, the backslash and the control characters escaped as +// Json requires. Strings from the application - object names, debug labels and the like - may contain +// any of these (a line break in a render pass name, say), and written as they are they make the whole +// file invalid. The runs between the characters that need escaping are written as they are. +inline void dump_json_string_w(ApiDumpFastWriter &writer, const char *text) { + writer << " \""; + const char *run = text; + const char *p = text; + for (; *p != '\0'; ++p) { + const unsigned char c = static_cast(*p); + if (c != '"' && c != '\\' && c >= 0x20) continue; + writer << std::string_view(run, static_cast(p - run)); + switch (c) { + case '"': + writer << "\\\""; + break; + case '\\': + writer << "\\\\"; + break; + case '\n': + writer << "\\n"; + break; + case '\r': + writer << "\\r"; + break; + case '\t': + writer << "\\t"; + break; + case '\b': + writer << "\\b"; + break; + case '\f': + writer << "\\f"; + break; + default: { + static constexpr char kHexDigits[] = "0123456789abcdef"; + const char escape[] = {'\\', 'u', '0', '0', kHexDigits[c >> 4], kHexDigits[c & 0xf]}; + writer << std::string_view(escape, sizeof(escape)); + break; + } + } + run = p + 1; + } + writer << std::string_view(run, static_cast(p - run)); + writer << '"'; +} + template void dump_value(const ApiDumpSettings &settings, T &&...values) { if constexpr (Format == ApiDumpFormat::Json) { @@ -2132,7 +2179,8 @@ void dump_char(const char *object, const ApiDumpSettings &settings, const char * else dump_value(settings, '"', object, '"'); } else if constexpr (Format == ApiDumpFormat::Json) { - dump_value(settings, (object != NULL ? object : "")); + ApiDumpFastWriter writer(settings.stream()); + dump_json_string_w(writer, object != NULL ? object : ""); } dump_end(settings, OutputConstruct::value, indents); }