| {"messages": [{"role": "system", "content": "You are a security engineer fixing a CVE. You are given the vulnerability description (symptom only) and the vulnerable source window. Author the MINIMAL fix as one or more SEARCH/REPLACE blocks. Follow these rules exactly:\n1. Each block is:\n<<<<<<< SEARCH\n<exact lines copied verbatim from the shown source window>\n=======\n<the replacement lines>\n>>>>>>> REPLACE\n2. The SEARCH text MUST appear verbatim in the shown source window \u2014 copy it exactly, including whitespace; do not invent or paraphrase it.\n3. Change as few lines as possible; keep the SEARCH span tight around the edit.\n4. Modify ONLY code visible in the shown source window.\n5. Output only the SEARCH/REPLACE block(s) with no other text.\n6. Prefer folding a new bound or check into an existing condition over adding a separate guard, when the upstream fix does so."}, {"role": "user", "content": "# CVE\nCVE-2025-40928: Heap out-of-bounds read (CWE-125) in the Perl XS module JSON::XS through 4.03. The decimal number fast-path parser json_atof_scan1() in XS.xs guards against deep recursion with `if (--maxdepth <= 0) while (((U8)*s - '0') < 10) ++s;`. The sub-expression `(U8)*s - '0'` is evaluated as a signed int, so for any input byte below '0' (0x00..0x2F, including the NUL string terminator) it is negative and the `< 10` test is true. When a sufficiently long number exhausts the recursion-depth limit, the digit-skip loop walks past the end of the NUL-terminated scalar buffer, reading adjacent heap memory until it reaches a byte >= ':'. Decoding attacker-supplied JSON containing a long numeric token therefore causes an out-of-bounds read (crash, possible information disclosure).\n\n# Vulnerable source (XS.xs)\n```c\n// convert offset pointer to character index, sv must be string\nstatic STRLEN\nptr_to_index (SV *sv, char *offset)\n{\n return SvUTF8 (sv)\n ? utf8_distance (offset, SvPVX (sv))\n : offset - SvPVX (sv);\n}\n\n/////////////////////////////////////////////////////////////////////////////\n// fp hell\n\n// scan a group of digits, and a trailing exponent\nstatic void\njson_atof_scan1 (const char *s, NV *accum, int *expo, int postdp, int maxdepth)\n{\n UV uaccum = 0;\n int eaccum = 0;\n\n // if we recurse too deep, skip all remaining digits\n // to avoid a stack overflow attack\n if (expect_false (--maxdepth <= 0))\n while (((U8)*s - '0') < 10)\n ++s;\n\n for (;;)\n {\n U8 dig = (U8)*s - '0';\n\n if (expect_false (dig >= 10))\n {\n if (dig == (U8)((U8)'.' - (U8)'0'))\n {\n ++s;\n json_atof_scan1 (s, accum, expo, 1, maxdepth);\n }\n else if ((dig | ' ') == 'e' - '0')\n {\n int exp2 = 0;\n int neg = 0;\n\n ++s;\n\n if (*s == '-')\n {\n ++s;\n neg = 1;\n }\n else if (*s == '+')\n ++s;\n\n while ((dig = (U8)*s - '0') < 10)\n exp2 = exp2 * 10 + *s++ - '0';\n\n *expo += neg ? -exp2 : exp2;\n }\n\n break;\n }\n\n ++s;\n\n uaccum = uaccum * 10 + dig;\n ++eaccum;\n\n // if we have too many digits, then recurse for more\n // we actually do this for rather few digits\n if (uaccum >= (UV_MAX - 9) / 10)\n {\n```"}, {"role": "assistant", "content": "<<<<<<< SEARCH\n // if we recurse too deep, skip all remaining digits\n // to avoid a stack overflow attack\n if (expect_false (--maxdepth <= 0))\n while (((U8)*s - '0') < 10)\n ++s;\n\n for (;;)\n {\n U8 dig = (U8)*s - '0';\n\n if (expect_false (dig >= 10))\n {\n if (dig == (U8)((U8)'.' - (U8)'0'))\n {\n ++s;\n json_atof_scan1 (s, accum, expo, 1, maxdepth);\n=======\n // if we recurse too deep, skip all remaining digits\n // to avoid a stack overflow attack\n if (expect_false (--maxdepth <= 0))\n while (*s >= '0' && *s <= '9')\n ++s;\n\n for (;;)\n {\n U8 dig = *s - '0';\n\n if (expect_false (dig >= 10))\n {\n if (dig == (U8)('.' - '0'))\n {\n ++s;\n json_atof_scan1 (s, accum, expo, 1, maxdepth);\n>>>>>>> REPLACE\n<<<<<<< SEARCH\n else if (*s == '+')\n ++s;\n\n while ((dig = (U8)*s - '0') < 10)\n exp2 = exp2 * 10 + *s++ - '0';\n\n *expo += neg ? -exp2 : exp2;\n }\n=======\n else if (*s == '+')\n ++s;\n\n while (*s >= '0' && *s <= '9')\n exp2 = exp2 * 10 + (*s++ - '0');\n\n *expo += neg ? -exp2 : exp2;\n }\n>>>>>>> REPLACE"}]} |
| {"messages": [{"role": "system", "content": "You are a security engineer fixing a CVE. You are given the vulnerability description (symptom only) and the vulnerable source window. Author the MINIMAL fix as one or more SEARCH/REPLACE blocks. Follow these rules exactly:\n1. Each block is:\n<<<<<<< SEARCH\n<exact lines copied verbatim from the shown source window>\n=======\n<the replacement lines>\n>>>>>>> REPLACE\n2. The SEARCH text MUST appear verbatim in the shown source window \u2014 copy it exactly, including whitespace; do not invent or paraphrase it.\n3. Change as few lines as possible; keep the SEARCH span tight around the edit.\n4. Modify ONLY code visible in the shown source window.\n5. Output only the SEARCH/REPLACE block(s) with no other text.\n6. Prefer folding a new bound or check into an existing condition over adding a separate guard, when the upstream fix does so."}, {"role": "user", "content": "# CVE\nCVE-2026-4539: ReDoS (Regular Expression Denial of Service, CWE-1333) in Pygments' Archetype Definition Language (ADL) lexer. Two regex patterns in pygments/lexers/archetype.py lacked quantifier upper bounds: (1) AtomsLexer 'archetype_id' rule used bare \\w+ inside nested alternation, enabling 2^N backtracking on crafted long identifiers; (2) AdlLexer 'GUID' rule used (\\d|[a-fA-F])+(-( \\d|[a-fA-F])+){3,}, an alternation-in-repetition pattern causing 2^N backtracking when the last segment contains a non-hex terminator. An attacker who controls input tokenized by the Pygments archetype lexer can cause indefinite CPU consumption.\n\n# Vulnerable source (pygments/lexers/archetype.py)\n```python\nfrom pygments.lexer import RegexLexer, include, bygroups, using, default\nfrom pygments.token import Text, Comment, Name, Literal, Number, String, \\\n Punctuation, Keyword, Operator, Generic, Whitespace\n\n__all__ = ['OdinLexer', 'CadlLexer', 'AdlLexer']\n\n\nclass AtomsLexer(RegexLexer):\n \"\"\"\n Lexer for Values used in ADL and ODIN.\n\n .. versionadded:: 2.1\n \"\"\"\n\n tokens = {\n # ----- pseudo-states for inclusion -----\n 'whitespace': [\n (r'\\n', Whitespace),\n (r'\\s+', Whitespace),\n (r'([ \\t]*)(--.*)$', bygroups(Whitespace, Comment)),\n ],\n 'archetype_id': [\n (r'([ \\t]*)(([a-zA-Z]\\w+(\\.[a-zA-Z]\\w+)*::)?[a-zA-Z]\\w+(-[a-zA-Z]\\w+){2}'\n r'\\.\\w+[\\w-]*\\.v\\d+(\\.\\d+){,2}((-[a-z]+)(\\.\\d+)?)?)',\n bygroups(Whitespace, Name.Decorator)),\n ],\n 'date_constraints': [\n # ISO 8601-based date/time constraints\n (r'[Xx?YyMmDdHhSs\\d]{2,4}([:-][Xx?YyMmDdHhSs\\d]{2}){2}', Literal.Date),\n # ISO 8601-based duration constraints + optional trailing slash\n (r'(P[YyMmWwDd]+(T[HhMmSs]+)?|PT[HhMmSs]+)/?', Literal.Date),\n ],\n 'ordered_values': [\n # ISO 8601 date with optional 'T' ligature\n (r'\\d{4}-\\d{2}-\\d{2}T?', Literal.Date),\n # ISO 8601 time\n (r'\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?([+-]\\d{4}|Z)?', Literal.Date),\n # ISO 8601 duration\n (r'P((\\d*(\\.\\d+)?[YyMmWwDd]){1,3}(T(\\d*(\\.\\d+)?[HhMmSs]){,3})?|'\n r'T(\\d*(\\.\\d+)?[HhMmSs]){,3})', Literal.Date),\n /* ... */\n (r'^([ \\t]*|[ \\t]+.*)\\n', using(OdinLexer)),\n (r'^([^\"]*\")(>[ \\t]*\\n)', bygroups(String, Punctuation)),\n # template overlay delimiter\n (r'^----------*\\n', Text, '#pop'),\n (r'^.*\\n', String),\n default('#pop'),\n ],\n 'cadl_section': [\n (r'^([ \\t]*|[ \\t]+.*)\\n', using(CadlLexer)),\n default('#pop'),\n ],\n 'rules_section': [\n (r'^[ \\t]+.*\\n', using(CadlLexer)),\n default('#pop'),\n ],\n 'metadata': [\n (r'\\)', Punctuation, '#pop'),\n (r';', Punctuation),\n (r'([Tt]rue|[Ff]alse)', Literal),\n # numbers and version ids\n (r'\\d+(\\.\\d+)*', Literal),\n # Guids\n (r'(\\d|[a-fA-F])+(-(\\d|[a-fA-F])+){3,}', Literal),\n (r'\\w+', Name.Class),\n (r'\"', String, 'string'),\n (r'=', Operator),\n (r'[ \\t]+', Whitespace),\n default('#pop'),\n ],\n 'root': [\n (r'^(archetype|template_overlay|operational_template|template|'\n r'speciali[sz]e)', Generic.Heading),\n (r'^(language|description|ontology|terminology|annotations|'\n r'component_terminologies|revision_history)[ \\t]*\\n',\n Generic.Heading, 'odin_section'),\n (r'^(definition)[ \\t]*\\n', Generic.Heading, 'cadl_section'),\n (r'^(rules)[ \\t]*\\n', Generic.Heading, 'rules_section'),\n include('archetype_id'),\n (r'([ \\t]*)(\\()', bygroups(Whitespace, Punctuation), 'metadata'),\n include('whitespace'),\n```"}, {"role": "assistant", "content": "<<<<<<< SEARCH\n (r'([ \\t]*)(--.*)$', bygroups(Whitespace, Comment)),\n ],\n 'archetype_id': [\n (r'([ \\t]*)(([a-zA-Z]\\w+(\\.[a-zA-Z]\\w+)*::)?[a-zA-Z]\\w+(-[a-zA-Z]\\w+){2}'\n r'\\.\\w+[\\w-]*\\.v\\d+(\\.\\d+){,2}((-[a-z]+)(\\.\\d+)?)?)',\n bygroups(Whitespace, Name.Decorator)),\n ],\n 'date_constraints': [\n=======\n (r'([ \\t]*)(--.*)$', bygroups(Whitespace, Comment)),\n ],\n 'archetype_id': [\n (r'([ \\t]*)(([a-zA-Z]\\w{1,100}(\\.[a-zA-Z]\\w{1,100})*::)?[a-zA-Z]\\w{1,100}(-[a-zA-Z]\\w{1,100}){2}'\n r'\\.\\w{1,100}[\\w-]*\\.v\\d+(\\.\\d+){,2}((-[a-z]+)(\\.\\d+)?)?)',\n bygroups(Whitespace, Name.Decorator)),\n ],\n 'date_constraints': [\n>>>>>>> REPLACE\n<<<<<<< SEARCH\n # numbers and version ids\n (r'\\d+(\\.\\d+)*', Literal),\n # Guids\n (r'(\\d|[a-fA-F])+(-(\\d|[a-fA-F])+){3,}', Literal),\n (r'\\w+', Name.Class),\n (r'\"', String, 'string'),\n (r'=', Operator),\n=======\n # numbers and version ids\n (r'\\d+(\\.\\d+)*', Literal),\n # Guids\n (r'[0-9a-fA-F]{1,36}(-[0-9a-fA-F]{1,36}){3,}', Literal),\n (r'\\w+', Name.Class),\n (r'\"', String, 'string'),\n (r'=', Operator),\n>>>>>>> REPLACE"}]} |