Skip to content

gguf-radar 0.1.5

Choose a tag to compare

@github-actions github-actions released this 30 Nov 11:26
· 5 commits to main since this release
f26f0a7

Security

  • Strings that a test on message content only requires to be absent, such as 'took ' in 'took ' not in content, are no longer listed as trigger words of conditional_logic_bomb, unless the if has an elif or else part, which runs when the string is present. not, not in, !=, and and or are followed, so double negations and De Morgan forms are read correctly. The finding and the verdict do not change. The description of a finding changes only where such a string is left out of the list trigger literal(s): [...], which happens only for an if without elif or else parts, and no sentence was added to any description. Every finding in the JSON report now has the keys trigger_literals, absent_literals, branch_text and known_template, which are empty for findings of other categories, so stored reports gain these fields. The printed output shows the strings and the text below a finding of this kind. branch_text holds up to 200 characters of the fixed text written in the branch itself, with the text of elif and else parts labelled. compare-template compares findings by severity, category and description, as before, and ignores the new fields.
  • A short list of known community templates, matched by the SHA-256 hash of the whole template text, in src/gguf_radar/known_templates.py. It holds 18 templates: the 16 template files of froggeric/Qwen-Fixed-Chat-Templates from v17 to v22.2 at revision 855bffc, and the chat template of NVIDIA Nemotron Nano v2 in the version of the NVIDIA repository and in the copy in llama.cpp. A template is listed only when the only effect of its reported branches is a warning inside the tool response, an empty thinking block that switches reasoning off for one reply, or a documented switch of the vendor. froggeric v15 and v16 are not listed, because they write text in the voice of the assistant at the start of its reply. Every reported branch in the listed templates, and every place that uses what the branch sets, is described next to the list. For a listed template, these branches give the new note known_template_branch instead of conditional_logic_bomb, and they do not change the verdict. All other findings apply in full. Only CRLF line ends and one trailing newline more or less are accepted as differences, so a modified copy stays SUSPICIOUS. scripts/known_template_hashes.py checks the hashes against the upstream files. On the two files of the report, the unmodified v21.3 template in nerun/OxCoder-9B-i1-MTP-GGUF now gives CLEAN with a note, and the copy in peculiar-ragdoll/Nail-Qwen3.6-35B-A3B-GGUF-MTP, which has a system prompt added to the template, stays SUSPICIOUS. Thanks to @nerun for the report in #25.
  • Scanning and sanitize cover named chat templates. A GGUF file can hold tokenizer.chat_template.<name> next to the default template, and llama.cpp uses a named template when a request needs it or when the default is empty. Before, scan read only the default key, so a payload in tokenizer.chat_template.tool_use gave CLEAN, and sanitize left the named keys in the file. Thanks to @agentik-os for the report in #21 and to @shiwng for the fix in #23.

Changed

  • The findings of every analyzed chat template are reported. Each finding has a new field template_key with the key of its template, and the printed findings name it. The result has a new field template_key with the key of the template with the highest risk score. The verdict is still the one of the worst finding. No field was renamed or removed.
  • The templates of a GGUF file are collected by one function, gguf_template_texts, which compare-template uses as well. compare-template now keeps a named template called default apart from the real default template, so the named one no longer replaces it.
  • scan reads the object form of chat_template in tokenizer_config.json, a mapping from names to templates, as it already read the list form. A list item without a name is read too.
  • sanitize --replace-template writes the new text under tokenizer.chat_template, adds the key if the file had none, and removes all named templates. --strip-template removes the default and all named templates. Both options also remove the array tokenizer.chat_templates, so it never lists a name without a template. The summary lists the removed keys in the new fields named_templates_removed and template_names_removed.
  • The default template and the template named tool_use are the two that llama.cpp reads, so a scan always analyzes them. A file that holds thousands of named templates or a very long template cannot make a scan slow, because the work is limited. Besides these two, a scan analyzes at most 16 named templates with at most 1,048,576 characters in total, and of any template it analyzes the first 1,048,576 characters. A file beyond a limit gets the finding too_many_chat_templates or chat_template_too_large and the verdict SUSPICIOUS. The fingerprint is still that of the whole template.
  • In tokenizer_config.json, the template named default is the default template, and two entries with the same name, or a nameless entry whose position equals another name, no longer replace each other. The Transformers library uses the last entry of a repeated name, and other runtimes may use the first, so every entry named default or tool_use is always analyzed, up to 4 entries for each name. For a name with more entries, the first 3 and the last one are analyzed, and the entries in between count against the limits for the other templates.
  • The scan of a repository and of a directory reads the files additional_chat_templates/<name>.jinja, which version 5 of the Transformers library loads as named templates. The files default.jinja and file.jinja set the default template in that library, and llama.cpp asks for tool_use, so these three files are always read. Of the other files, at most 16 are read, and a folder with more files gets the finding too_many_chat_templates. Their findings name the key chat_template.<name>, or chat_template for default.jinja and file.jinja. Only regular files are read, so a directory named x.jinja is skipped, and a file in the folder that is also found by the directory scan is scanned once.
  • A local file that is not a regular file, such as a symbolic link to /dev/zero or a named pipe, gives ERROR in scan, compare-template and sanitize, and does not exhaust memory or wait forever. A .jinja template file is read up to 4 MiB, and a JSON template file up to 16 MiB, in a local scan and in a scan of a repository alike. A longer file gets the finding chat_template_too_large and the verdict SUSPICIOUS, so a payload after the limit is not reported as CLEAN. The list file of scan -l, the replacement template of sanitize and a local base file of compare-template are read only if they are regular files, so a named pipe gives an error and does not wait forever. Files are opened in binary mode on Windows, and the tests run on Windows in CI.
  • tests/test_performance.py has scan-time tests for a file with many metadata entries and named templates, a file with a tensor section of 48 MB and templates at and beyond the limits. The tests of the limits compare a scan with the limits to a scan without them. The other tests use bounds that are several times the time on a development machine.
  • The reading of a template list or mapping in a JSON file is bounded. Only the first three and the last entry named default, the first three and the last entry named tool_use, and the first 16 other entries are kept, and all other entries are counted in one too_many_chat_templates finding without storing their text. The time to read such a file grows in proportion to the number of entries. The JSON limit is 16 MiB, because 16 MiB of small objects need about 500 MB of memory while they are parsed.

Full changelog: v0.1.4...v0.1.5