prompt
stringclasses
1 value
completions
listlengths
2
1.33k
labels
listlengths
2
1.33k
source
stringclasses
1 value
other_info
dict
index
int64
0
719
cwe
stringclasses
9 values
language
stringclasses
6 values
Determine whether the {function_name} code is vulnerable or not.
[ "S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state,\n regnode ** node_p,\n UV * code_point_p,\n int * cp_count,\n I32 * flagp,\n const bool strict,\n const U32 depth\n )\n{\n /* This routine teases apart the various meanings of \\N and returns\n * accordingly. The input parameters constrain which meaning(s) is/are valid\n * in the current context.\n *\n * Exactly one of <node_p> and <code_point_p> must be non-NULL.\n *\n * If <code_point_p> is not NULL, the context is expecting the result to be a\n * single code point. If this \\N instance turns out to a single code point,\n * the function returns TRUE and sets *code_point_p to that code point.\n *\n * If <node_p> is not NULL, the context is expecting the result to be one of\n * the things representable by a regnode. If this \\N instance turns out to be\n * one such, the function generates the regnode, returns TRUE and sets *node_p\n * to point to that regnode.\n *\n * If this instance of \\N isn't legal in any context, this function will\n * generate a fatal error and not return.\n *\n * On input, RExC_parse should point to the first char following the \\N at the\n * time of the call. On successful return, RExC_parse will have been updated\n * to point to just after the sequence identified by this routine. Also\n * *flagp has been updated as needed.\n *\n * When there is some problem with the current context and this \\N instance,\n * the function returns FALSE, without advancing RExC_parse, nor setting\n * *node_p, nor *code_point_p, nor *flagp.\n *\n * If <cp_count> is not NULL, the caller wants to know the length (in code\n * points) that this \\N sequence matches. This is set even if the function\n * returns FALSE, as detailed below.\n *\n * There are 5 possibilities here, as detailed in the next 5 paragraphs.\n *\n * Probably the most common case is for the \\N to specify a single code point.\n * *cp_count will be set to 1, and *code_point_p will be set to that code\n * point.\n *\n * Another possibility is for the input to be an empty \\N{}, which for\n * backwards compatibility we accept. *cp_count will be set to 0. *node_p\n * will be set to a generated NOTHING node.\n *\n * Still another possibility is for the \\N to mean [^\\n]. *cp_count will be\n * set to 0. *node_p will be set to a generated REG_ANY node.\n *\n * The fourth possibility is that \\N resolves to a sequence of more than one\n * code points. *cp_count will be set to the number of code points in the\n * sequence. *node_p * will be set to a generated node returned by this\n * function calling S_reg().\n *\n * The final possibility is that it is premature to be calling this function;\n * that pass1 needs to be restarted. This can happen when this changes from\n * /d to /u rules, or when the pattern needs to be upgraded to UTF-8. The\n * latter occurs only when the fourth possibility would otherwise be in\n * effect, and is because one of those code points requires the pattern to be\n * recompiled as UTF-8. The function returns FALSE, and sets the\n * RESTART_PASS1 and NEED_UTF8 flags in *flagp, as appropriate. When this\n * happens, the caller needs to desist from continuing parsing, and return\n * this information to its caller. This is not set for when there is only one\n * code point, as this can be called as part of an ANYOF node, and they can\n * store above-Latin1 code points without the pattern having to be in UTF-8.\n *\n * For non-single-quoted regexes, the tokenizer has resolved character and\n * sequence names inside \\N{...} into their Unicode values, normalizing the\n * result into what we should see here: '\\N{U+c1.c2...}', where c1... are the\n * hex-represented code points in the sequence. This is done there because\n * the names can vary based on what charnames pragma is in scope at the time,\n * so we need a way to take a snapshot of what they resolve to at the time of\n * the original parse. [perl #56444].\n *\n * That parsing is skipped for single-quoted regexes, so we may here get\n * '\\N{NAME}'. This is a fatal error. These names have to be resolved by the\n * parser. But if the single-quoted regex is something like '\\N{U+41}', that\n * is legal and handled here. The code point is Unicode, and has to be\n * translated into the native character set for non-ASCII platforms.\n */", " char * endbrace; /* points to '}' following the name */\n char *endchar;\t/* Points to '.' or '}' ending cur char in the input\n stream */\n char* p = RExC_parse; /* Temporary */", " GET_RE_DEBUG_FLAGS_DECL;", " PERL_ARGS_ASSERT_GROK_BSLASH_N;", " GET_RE_DEBUG_FLAGS;", " assert(cBOOL(node_p) ^ cBOOL(code_point_p)); /* Exactly one should be set */\n assert(! (node_p && cp_count)); /* At most 1 should be set */", " if (cp_count) { /* Initialize return for the most common case */\n *cp_count = 1;\n }", " /* The [^\\n] meaning of \\N ignores spaces and comments under the /x\n * modifier. The other meanings do not, so use a temporary until we find\n * out which we are being called with */\n skip_to_be_ignored_text(pRExC_state, &p,\n FALSE /* Don't force to /x */ );", " /* Disambiguate between \\N meaning a named character versus \\N meaning\n * [^\\n]. The latter is assumed when the {...} following the \\N is a legal\n * quantifier, or there is no '{' at all */\n if (*p != '{' || regcurly(p)) {\n\tRExC_parse = p;\n if (cp_count) {\n *cp_count = -1;\n }", "\tif (! node_p) {\n return FALSE;\n }", "\t*node_p = reg_node(pRExC_state, REG_ANY);\n\t*flagp |= HASWIDTH|SIMPLE;\n\tMARK_NAUGHTY(1);\n Set_Node_Length(*node_p, 1); /* MJD */\n\treturn TRUE;\n }", " /* Here, we have decided it should be a named character or sequence */", " /* The test above made sure that the next real character is a '{', but\n * under the /x modifier, it could be separated by space (or a comment and\n * \\n) and this is not allowed (for consistency with \\x{...} and the\n * tokenizer handling of \\N{NAME}). */\n if (*RExC_parse != '{') {\n\tvFAIL(\"Missing braces on \\\\N{}\");\n }", " RExC_parse++;\t/* Skip past the '{' */\n", " endbrace = strchr(RExC_parse, '}');", " if (! endbrace) { /* no trailing brace */\n vFAIL2(\"Missing right brace on \\\\%c{}\", 'N');\n }\n else if (!( endbrace == RExC_parse\t/* nothing between the {} */\n || memBEGINs(RExC_parse, /* U+ (bad hex is checked below\n for a better error msg) */\n (STRLEN) (RExC_end - RExC_parse),\n \"U+\")))\n {\n\tRExC_parse = endbrace;\t/* position msg's '<--HERE' */\n\tvFAIL(\"\\\\N{NAME} must be resolved by the lexer\");\n }", " REQUIRE_UNI_RULES(flagp, FALSE); /* Unicode named chars imply Unicode\n semantics */", " if (endbrace == RExC_parse) { /* empty: \\N{} */\n if (strict) {\n RExC_parse++; /* Position after the \"}\" */\n vFAIL(\"Zero length \\\\N{}\");\n }\n if (cp_count) {\n *cp_count = 0;\n }\n nextchar(pRExC_state);\n\tif (! node_p) {\n return FALSE;\n }", " *node_p = reg_node(pRExC_state,NOTHING);\n return TRUE;\n }", " RExC_parse += 2;\t/* Skip past the 'U+' */", " /* Because toke.c has generated a special construct for us guaranteed not\n * to have NULs, we can use a str function */\n endchar = RExC_parse + strcspn(RExC_parse, \".}\");", " /* Code points are separated by dots. If none, there is only one code\n * point, and is terminated by the brace */", " if (endchar >= endbrace) {\n\tSTRLEN length_of_hex;\n\tI32 grok_hex_flags;", " /* Here, exactly one code point. If that isn't what is wanted, fail */\n if (! code_point_p) {\n RExC_parse = p;\n return FALSE;\n }", " /* Convert code point from hex */\n\tlength_of_hex = (STRLEN)(endchar - RExC_parse);\n\tgrok_hex_flags = PERL_SCAN_ALLOW_UNDERSCORES\n | PERL_SCAN_DISALLOW_PREFIX", " /* No errors in the first pass (See [perl\n * #122671].) We let the code below find the\n * errors when there are multiple chars. */\n | ((SIZE_ONLY)\n ? PERL_SCAN_SILENT_ILLDIGIT\n : 0);", " /* This routine is the one place where both single- and double-quotish\n * \\N{U+xxxx} are evaluated. The value is a Unicode code point which\n * must be converted to native. */\n\t*code_point_p = UNI_TO_NATIVE(grok_hex(RExC_parse,\n &length_of_hex,\n &grok_hex_flags,\n NULL));", "\t/* The tokenizer should have guaranteed validity, but it's possible to\n * bypass it by using single quoting, so check. Don't do the check\n * here when there are multiple chars; we do it below anyway. */\n if (length_of_hex == 0\n || length_of_hex != (STRLEN)(endchar - RExC_parse) )\n {\n RExC_parse += length_of_hex;\t/* Includes all the valid */\n RExC_parse += (RExC_orig_utf8)\t/* point to after 1st invalid */\n ? UTF8SKIP(RExC_parse)\n : 1;\n /* Guard against malformed utf8 */\n if (RExC_parse >= endchar) {\n RExC_parse = endchar;\n }\n vFAIL(\"Invalid hexadecimal number in \\\\N{U+...}\");\n }", " RExC_parse = endbrace + 1;\n return TRUE;\n }\n else { /* Is a multiple character sequence */\n\tSV * substitute_parse;\n\tSTRLEN len;\n\tchar *orig_end = RExC_end;\n\tchar *save_start = RExC_start;\n I32 flags;", " /* Count the code points, if desired, in the sequence */\n if (cp_count) {\n *cp_count = 0;\n while (RExC_parse < endbrace) {\n /* Point to the beginning of the next character in the sequence. */\n RExC_parse = endchar + 1;\n endchar = RExC_parse + strcspn(RExC_parse, \".}\");\n (*cp_count)++;\n }\n }", " /* Fail if caller doesn't want to handle a multi-code-point sequence.\n * But don't backup up the pointer if the caller wants to know how many\n * code points there are (they can then handle things) */\n if (! node_p) {\n if (! cp_count) {\n RExC_parse = p;\n }\n return FALSE;\n }", "\t/* What is done here is to convert this to a sub-pattern of the form\n * \\x{char1}\\x{char2}... and then call reg recursively to parse it\n * (enclosing in \"(?: ... )\" ). That way, it retains its atomicness,\n * while not having to worry about special handling that some code\n * points may have. */", "\tsubstitute_parse = newSVpvs(\"?:\");", "\twhile (RExC_parse < endbrace) {", "\t /* Convert to notation the rest of the code understands */\n\t sv_catpv(substitute_parse, \"\\\\x{\");\n\t sv_catpvn(substitute_parse, RExC_parse, endchar - RExC_parse);\n\t sv_catpv(substitute_parse, \"}\");", "\t /* Point to the beginning of the next character in the sequence. */\n\t RExC_parse = endchar + 1;\n\t endchar = RExC_parse + strcspn(RExC_parse, \".}\");", "\t}\n sv_catpv(substitute_parse, \")\");", " len = SvCUR(substitute_parse);", "\t/* Don't allow empty number */\n\tif (len < (STRLEN) 8) {\n RExC_parse = endbrace;\n\t vFAIL(\"Invalid hexadecimal number in \\\\N{U+...}\");\n\t}", " RExC_parse = RExC_start = RExC_adjusted_start\n = SvPV_nolen(substitute_parse);\n\tRExC_end = RExC_parse + len;", " /* The values are Unicode, and therefore not subject to recoding, but\n * have to be converted to native on a non-Unicode (meaning non-ASCII)\n * platform. */\n#ifdef EBCDIC\n RExC_recode_x_to_native = 1;\n#endif", " *node_p = reg(pRExC_state, 1, &flags, depth+1);", " /* Restore the saved values */\n\tRExC_start = RExC_adjusted_start = save_start;\n\tRExC_parse = endbrace;\n\tRExC_end = orig_end;\n#ifdef EBCDIC\n RExC_recode_x_to_native = 0;\n#endif\n SvREFCNT_dec_NN(substitute_parse);", " if (! *node_p) {\n if (flags & (RESTART_PASS1|NEED_UTF8)) {\n *flagp = flags & (RESTART_PASS1|NEED_UTF8);\n return FALSE;\n }\n FAIL2(\"panic: reg returned NULL to grok_bslash_N, flags=%#\" UVxf,\n (UV) flags);\n }\n *flagp |= flags&(HASWIDTH|SPSTART|SIMPLE|POSTPONED);", " nextchar(pRExC_state);", " return TRUE;\n }\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 6272, "char_start": 6268, "chars": "(cha" }, { "char_end": 6280, "char_start": 6273, "chars": " *) mem" }, { "char_end": 6322, "char_start": 6299, "chars": ", RExC_end - RExC_parse" } ], "deleted": [ { "char_end": 6270, "char_start": 6268, "chars": "st" } ] }, "commit_link": "github.com/Perl/perl5/commit/43b2f4ef399e2fd7240b4eeb0658686ad95f8e62", "file_name": "regcomp.c", "func_name": "S_grok_bslash_N", "line_changes": { "added": [ { "char_end": 6325, "char_start": 6253, "line": " endbrace = (char *) memchr(RExC_parse, '}', RExC_end - RExC_parse);\n", "line_no": 142 } ], "deleted": [ { "char_end": 6293, "char_start": 6253, "line": " endbrace = strchr(RExC_parse, '}');\n", "line_no": 142 } ] }, "vul_type": "cwe-125" }
450
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state,\n regnode ** node_p,\n UV * code_point_p,\n int * cp_count,\n I32 * flagp,\n const bool strict,\n const U32 depth\n )\n{\n /* This routine teases apart the various meanings of \\N and returns\n * accordingly. The input parameters constrain which meaning(s) is/are valid\n * in the current context.\n *\n * Exactly one of <node_p> and <code_point_p> must be non-NULL.\n *\n * If <code_point_p> is not NULL, the context is expecting the result to be a\n * single code point. If this \\N instance turns out to a single code point,\n * the function returns TRUE and sets *code_point_p to that code point.\n *\n * If <node_p> is not NULL, the context is expecting the result to be one of\n * the things representable by a regnode. If this \\N instance turns out to be\n * one such, the function generates the regnode, returns TRUE and sets *node_p\n * to point to that regnode.\n *\n * If this instance of \\N isn't legal in any context, this function will\n * generate a fatal error and not return.\n *\n * On input, RExC_parse should point to the first char following the \\N at the\n * time of the call. On successful return, RExC_parse will have been updated\n * to point to just after the sequence identified by this routine. Also\n * *flagp has been updated as needed.\n *\n * When there is some problem with the current context and this \\N instance,\n * the function returns FALSE, without advancing RExC_parse, nor setting\n * *node_p, nor *code_point_p, nor *flagp.\n *\n * If <cp_count> is not NULL, the caller wants to know the length (in code\n * points) that this \\N sequence matches. This is set even if the function\n * returns FALSE, as detailed below.\n *\n * There are 5 possibilities here, as detailed in the next 5 paragraphs.\n *\n * Probably the most common case is for the \\N to specify a single code point.\n * *cp_count will be set to 1, and *code_point_p will be set to that code\n * point.\n *\n * Another possibility is for the input to be an empty \\N{}, which for\n * backwards compatibility we accept. *cp_count will be set to 0. *node_p\n * will be set to a generated NOTHING node.\n *\n * Still another possibility is for the \\N to mean [^\\n]. *cp_count will be\n * set to 0. *node_p will be set to a generated REG_ANY node.\n *\n * The fourth possibility is that \\N resolves to a sequence of more than one\n * code points. *cp_count will be set to the number of code points in the\n * sequence. *node_p * will be set to a generated node returned by this\n * function calling S_reg().\n *\n * The final possibility is that it is premature to be calling this function;\n * that pass1 needs to be restarted. This can happen when this changes from\n * /d to /u rules, or when the pattern needs to be upgraded to UTF-8. The\n * latter occurs only when the fourth possibility would otherwise be in\n * effect, and is because one of those code points requires the pattern to be\n * recompiled as UTF-8. The function returns FALSE, and sets the\n * RESTART_PASS1 and NEED_UTF8 flags in *flagp, as appropriate. When this\n * happens, the caller needs to desist from continuing parsing, and return\n * this information to its caller. This is not set for when there is only one\n * code point, as this can be called as part of an ANYOF node, and they can\n * store above-Latin1 code points without the pattern having to be in UTF-8.\n *\n * For non-single-quoted regexes, the tokenizer has resolved character and\n * sequence names inside \\N{...} into their Unicode values, normalizing the\n * result into what we should see here: '\\N{U+c1.c2...}', where c1... are the\n * hex-represented code points in the sequence. This is done there because\n * the names can vary based on what charnames pragma is in scope at the time,\n * so we need a way to take a snapshot of what they resolve to at the time of\n * the original parse. [perl #56444].\n *\n * That parsing is skipped for single-quoted regexes, so we may here get\n * '\\N{NAME}'. This is a fatal error. These names have to be resolved by the\n * parser. But if the single-quoted regex is something like '\\N{U+41}', that\n * is legal and handled here. The code point is Unicode, and has to be\n * translated into the native character set for non-ASCII platforms.\n */", " char * endbrace; /* points to '}' following the name */\n char *endchar;\t/* Points to '.' or '}' ending cur char in the input\n stream */\n char* p = RExC_parse; /* Temporary */", " GET_RE_DEBUG_FLAGS_DECL;", " PERL_ARGS_ASSERT_GROK_BSLASH_N;", " GET_RE_DEBUG_FLAGS;", " assert(cBOOL(node_p) ^ cBOOL(code_point_p)); /* Exactly one should be set */\n assert(! (node_p && cp_count)); /* At most 1 should be set */", " if (cp_count) { /* Initialize return for the most common case */\n *cp_count = 1;\n }", " /* The [^\\n] meaning of \\N ignores spaces and comments under the /x\n * modifier. The other meanings do not, so use a temporary until we find\n * out which we are being called with */\n skip_to_be_ignored_text(pRExC_state, &p,\n FALSE /* Don't force to /x */ );", " /* Disambiguate between \\N meaning a named character versus \\N meaning\n * [^\\n]. The latter is assumed when the {...} following the \\N is a legal\n * quantifier, or there is no '{' at all */\n if (*p != '{' || regcurly(p)) {\n\tRExC_parse = p;\n if (cp_count) {\n *cp_count = -1;\n }", "\tif (! node_p) {\n return FALSE;\n }", "\t*node_p = reg_node(pRExC_state, REG_ANY);\n\t*flagp |= HASWIDTH|SIMPLE;\n\tMARK_NAUGHTY(1);\n Set_Node_Length(*node_p, 1); /* MJD */\n\treturn TRUE;\n }", " /* Here, we have decided it should be a named character or sequence */", " /* The test above made sure that the next real character is a '{', but\n * under the /x modifier, it could be separated by space (or a comment and\n * \\n) and this is not allowed (for consistency with \\x{...} and the\n * tokenizer handling of \\N{NAME}). */\n if (*RExC_parse != '{') {\n\tvFAIL(\"Missing braces on \\\\N{}\");\n }", " RExC_parse++;\t/* Skip past the '{' */\n", " endbrace = (char *) memchr(RExC_parse, '}', RExC_end - RExC_parse);", " if (! endbrace) { /* no trailing brace */\n vFAIL2(\"Missing right brace on \\\\%c{}\", 'N');\n }\n else if (!( endbrace == RExC_parse\t/* nothing between the {} */\n || memBEGINs(RExC_parse, /* U+ (bad hex is checked below\n for a better error msg) */\n (STRLEN) (RExC_end - RExC_parse),\n \"U+\")))\n {\n\tRExC_parse = endbrace;\t/* position msg's '<--HERE' */\n\tvFAIL(\"\\\\N{NAME} must be resolved by the lexer\");\n }", " REQUIRE_UNI_RULES(flagp, FALSE); /* Unicode named chars imply Unicode\n semantics */", " if (endbrace == RExC_parse) { /* empty: \\N{} */\n if (strict) {\n RExC_parse++; /* Position after the \"}\" */\n vFAIL(\"Zero length \\\\N{}\");\n }\n if (cp_count) {\n *cp_count = 0;\n }\n nextchar(pRExC_state);\n\tif (! node_p) {\n return FALSE;\n }", " *node_p = reg_node(pRExC_state,NOTHING);\n return TRUE;\n }", " RExC_parse += 2;\t/* Skip past the 'U+' */", " /* Because toke.c has generated a special construct for us guaranteed not\n * to have NULs, we can use a str function */\n endchar = RExC_parse + strcspn(RExC_parse, \".}\");", " /* Code points are separated by dots. If none, there is only one code\n * point, and is terminated by the brace */", " if (endchar >= endbrace) {\n\tSTRLEN length_of_hex;\n\tI32 grok_hex_flags;", " /* Here, exactly one code point. If that isn't what is wanted, fail */\n if (! code_point_p) {\n RExC_parse = p;\n return FALSE;\n }", " /* Convert code point from hex */\n\tlength_of_hex = (STRLEN)(endchar - RExC_parse);\n\tgrok_hex_flags = PERL_SCAN_ALLOW_UNDERSCORES\n | PERL_SCAN_DISALLOW_PREFIX", " /* No errors in the first pass (See [perl\n * #122671].) We let the code below find the\n * errors when there are multiple chars. */\n | ((SIZE_ONLY)\n ? PERL_SCAN_SILENT_ILLDIGIT\n : 0);", " /* This routine is the one place where both single- and double-quotish\n * \\N{U+xxxx} are evaluated. The value is a Unicode code point which\n * must be converted to native. */\n\t*code_point_p = UNI_TO_NATIVE(grok_hex(RExC_parse,\n &length_of_hex,\n &grok_hex_flags,\n NULL));", "\t/* The tokenizer should have guaranteed validity, but it's possible to\n * bypass it by using single quoting, so check. Don't do the check\n * here when there are multiple chars; we do it below anyway. */\n if (length_of_hex == 0\n || length_of_hex != (STRLEN)(endchar - RExC_parse) )\n {\n RExC_parse += length_of_hex;\t/* Includes all the valid */\n RExC_parse += (RExC_orig_utf8)\t/* point to after 1st invalid */\n ? UTF8SKIP(RExC_parse)\n : 1;\n /* Guard against malformed utf8 */\n if (RExC_parse >= endchar) {\n RExC_parse = endchar;\n }\n vFAIL(\"Invalid hexadecimal number in \\\\N{U+...}\");\n }", " RExC_parse = endbrace + 1;\n return TRUE;\n }\n else { /* Is a multiple character sequence */\n\tSV * substitute_parse;\n\tSTRLEN len;\n\tchar *orig_end = RExC_end;\n\tchar *save_start = RExC_start;\n I32 flags;", " /* Count the code points, if desired, in the sequence */\n if (cp_count) {\n *cp_count = 0;\n while (RExC_parse < endbrace) {\n /* Point to the beginning of the next character in the sequence. */\n RExC_parse = endchar + 1;\n endchar = RExC_parse + strcspn(RExC_parse, \".}\");\n (*cp_count)++;\n }\n }", " /* Fail if caller doesn't want to handle a multi-code-point sequence.\n * But don't backup up the pointer if the caller wants to know how many\n * code points there are (they can then handle things) */\n if (! node_p) {\n if (! cp_count) {\n RExC_parse = p;\n }\n return FALSE;\n }", "\t/* What is done here is to convert this to a sub-pattern of the form\n * \\x{char1}\\x{char2}... and then call reg recursively to parse it\n * (enclosing in \"(?: ... )\" ). That way, it retains its atomicness,\n * while not having to worry about special handling that some code\n * points may have. */", "\tsubstitute_parse = newSVpvs(\"?:\");", "\twhile (RExC_parse < endbrace) {", "\t /* Convert to notation the rest of the code understands */\n\t sv_catpv(substitute_parse, \"\\\\x{\");\n\t sv_catpvn(substitute_parse, RExC_parse, endchar - RExC_parse);\n\t sv_catpv(substitute_parse, \"}\");", "\t /* Point to the beginning of the next character in the sequence. */\n\t RExC_parse = endchar + 1;\n\t endchar = RExC_parse + strcspn(RExC_parse, \".}\");", "\t}\n sv_catpv(substitute_parse, \")\");", " len = SvCUR(substitute_parse);", "\t/* Don't allow empty number */\n\tif (len < (STRLEN) 8) {\n RExC_parse = endbrace;\n\t vFAIL(\"Invalid hexadecimal number in \\\\N{U+...}\");\n\t}", " RExC_parse = RExC_start = RExC_adjusted_start\n = SvPV_nolen(substitute_parse);\n\tRExC_end = RExC_parse + len;", " /* The values are Unicode, and therefore not subject to recoding, but\n * have to be converted to native on a non-Unicode (meaning non-ASCII)\n * platform. */\n#ifdef EBCDIC\n RExC_recode_x_to_native = 1;\n#endif", " *node_p = reg(pRExC_state, 1, &flags, depth+1);", " /* Restore the saved values */\n\tRExC_start = RExC_adjusted_start = save_start;\n\tRExC_parse = endbrace;\n\tRExC_end = orig_end;\n#ifdef EBCDIC\n RExC_recode_x_to_native = 0;\n#endif\n SvREFCNT_dec_NN(substitute_parse);", " if (! *node_p) {\n if (flags & (RESTART_PASS1|NEED_UTF8)) {\n *flagp = flags & (RESTART_PASS1|NEED_UTF8);\n return FALSE;\n }\n FAIL2(\"panic: reg returned NULL to grok_bslash_N, flags=%#\" UVxf,\n (UV) flags);\n }\n *flagp |= flags&(HASWIDTH|SPSTART|SIMPLE|POSTPONED);", " nextchar(pRExC_state);", " return TRUE;\n }\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 6272, "char_start": 6268, "chars": "(cha" }, { "char_end": 6280, "char_start": 6273, "chars": " *) mem" }, { "char_end": 6322, "char_start": 6299, "chars": ", RExC_end - RExC_parse" } ], "deleted": [ { "char_end": 6270, "char_start": 6268, "chars": "st" } ] }, "commit_link": "github.com/Perl/perl5/commit/43b2f4ef399e2fd7240b4eeb0658686ad95f8e62", "file_name": "regcomp.c", "func_name": "S_grok_bslash_N", "line_changes": { "added": [ { "char_end": 6325, "char_start": 6253, "line": " endbrace = (char *) memchr(RExC_parse, '}', RExC_end - RExC_parse);\n", "line_no": 142 } ], "deleted": [ { "char_end": 6293, "char_start": 6253, "line": " endbrace = strchr(RExC_parse, '}');\n", "line_no": 142 } ] }, "vul_type": "cwe-125" }
450
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "ssize_t enc_untrusted_read(int fd, void *buf, size_t count) {", " return static_cast<ssize_t>(EnsureInitializedAndDispatchSyscall(", " asylo::system_call::kSYS_read, fd, buf, count));", "", "}" ]
[ 1, 0, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 68, "char_start": 64, "chars": "ssiz" }, { "char_end": 70, "char_start": 69, "chars": "_" }, { "char_end": 72, "char_start": 71, "chars": " " }, { "char_end": 77, "char_start": 73, "chars": "et =" }, { "char_end": 364, "char_start": 189, "chars": ";\n if (ret != -1 && ret > count) {\n ::asylo::primitives::TrustedPrimitives::BestEffortAbort(\n \"enc_untrusted_read: read result exceeds requested\");\n }\n return ret" } ], "deleted": [ { "char_end": 70, "char_start": 67, "chars": "urn" } ] }, "commit_link": "github.com/google/asylo/commit/b1d120a2c7d7446d2cc58d517e20a1b184b82200", "file_name": "asylo/platform/host_call/trusted/host_calls.cc", "func_name": "enc_untrusted_read", "line_changes": { "added": [ { "char_end": 136, "char_start": 62, "line": " ssize_t ret = static_cast<ssize_t>(EnsureInitializedAndDispatchSyscall(\n", "line_no": 2 }, { "char_end": 225, "char_start": 191, "line": " if (ret != -1 && ret > count) {\n", "line_no": 4 }, { "char_end": 286, "char_start": 225, "line": " ::asylo::primitives::TrustedPrimitives::BestEffortAbort(\n", "line_no": 5 }, { "char_end": 348, "char_start": 286, "line": " \"enc_untrusted_read: read result exceeds requested\");\n", "line_no": 6 }, { "char_end": 352, "char_start": 348, "line": " }\n", "line_no": 7 }, { "char_end": 366, "char_start": 352, "line": " return ret;\n", "line_no": 8 } ], "deleted": [ { "char_end": 129, "char_start": 62, "line": " return static_cast<ssize_t>(EnsureInitializedAndDispatchSyscall(\n", "line_no": 2 } ] }, "vul_type": "cwe-125" }
451
cwe-125
cc
Determine whether the {function_name} code is vulnerable or not.
[ "ssize_t enc_untrusted_read(int fd, void *buf, size_t count) {", " ssize_t ret = static_cast<ssize_t>(EnsureInitializedAndDispatchSyscall(", " asylo::system_call::kSYS_read, fd, buf, count));", " if (ret != -1 && ret > count) {\n ::asylo::primitives::TrustedPrimitives::BestEffortAbort(\n \"enc_untrusted_read: read result exceeds requested\");\n }\n return ret;", "}" ]
[ 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 68, "char_start": 64, "chars": "ssiz" }, { "char_end": 70, "char_start": 69, "chars": "_" }, { "char_end": 72, "char_start": 71, "chars": " " }, { "char_end": 77, "char_start": 73, "chars": "et =" }, { "char_end": 364, "char_start": 189, "chars": ";\n if (ret != -1 && ret > count) {\n ::asylo::primitives::TrustedPrimitives::BestEffortAbort(\n \"enc_untrusted_read: read result exceeds requested\");\n }\n return ret" } ], "deleted": [ { "char_end": 70, "char_start": 67, "chars": "urn" } ] }, "commit_link": "github.com/google/asylo/commit/b1d120a2c7d7446d2cc58d517e20a1b184b82200", "file_name": "asylo/platform/host_call/trusted/host_calls.cc", "func_name": "enc_untrusted_read", "line_changes": { "added": [ { "char_end": 136, "char_start": 62, "line": " ssize_t ret = static_cast<ssize_t>(EnsureInitializedAndDispatchSyscall(\n", "line_no": 2 }, { "char_end": 225, "char_start": 191, "line": " if (ret != -1 && ret > count) {\n", "line_no": 4 }, { "char_end": 286, "char_start": 225, "line": " ::asylo::primitives::TrustedPrimitives::BestEffortAbort(\n", "line_no": 5 }, { "char_end": 348, "char_start": 286, "line": " \"enc_untrusted_read: read result exceeds requested\");\n", "line_no": 6 }, { "char_end": 352, "char_start": 348, "line": " }\n", "line_no": 7 }, { "char_end": 366, "char_start": 352, "line": " return ret;\n", "line_no": 8 } ], "deleted": [ { "char_end": 129, "char_start": 62, "line": " return static_cast<ssize_t>(EnsureInitializedAndDispatchSyscall(\n", "line_no": 2 } ] }, "vul_type": "cwe-125" }
451
cwe-125
cc
Determine whether the {function_name} code is vulnerable or not.
[ "int WavpackVerifySingleBlock (unsigned char *buffer, int verify_checksum)\n{\n WavpackHeader *wphdr = (WavpackHeader *) buffer;\n uint32_t checksum_passed = 0, bcount, meta_bc;\n unsigned char *dp, meta_id, c1, c2;", " if (strncmp (wphdr->ckID, \"wvpk\", 4) || wphdr->ckSize + 8 < sizeof (WavpackHeader))\n return FALSE;", " bcount = wphdr->ckSize - sizeof (WavpackHeader) + 8;\n dp = (unsigned char *)(wphdr + 1);", " while (bcount >= 2) {\n meta_id = *dp++;\n c1 = *dp++;", " meta_bc = c1 << 1;\n bcount -= 2;", " if (meta_id & ID_LARGE) {\n if (bcount < 2)\n return FALSE;", " c1 = *dp++;\n c2 = *dp++;\n meta_bc += ((uint32_t) c1 << 9) + ((uint32_t) c2 << 17);\n bcount -= 2;\n }", " if (bcount < meta_bc)\n return FALSE;", " if (verify_checksum && (meta_id & ID_UNIQUE) == ID_BLOCK_CHECKSUM) {\n#ifdef BITSTREAM_SHORTS\n uint16_t *csptr = (uint16_t*) buffer;\n#else\n unsigned char *csptr = buffer;\n#endif\n int wcount = (int)(dp - 2 - buffer) >> 1;\n uint32_t csum = (uint32_t) -1;", " if ((meta_id & ID_ODD_SIZE) || meta_bc < 2 || meta_bc > 4)\n return FALSE;", "#ifdef BITSTREAM_SHORTS\n while (wcount--)\n csum = (csum * 3) + *csptr++;\n#else\n WavpackNativeToLittleEndian ((WavpackHeader *) buffer, WavpackHeaderFormat);", " while (wcount--) {\n csum = (csum * 3) + csptr [0] + (csptr [1] << 8);\n csptr += 2;\n }", " WavpackLittleEndianToNative ((WavpackHeader *) buffer, WavpackHeaderFormat);\n#endif", " if (meta_bc == 4) {", " if (*dp++ != (csum & 0xff) || *dp++ != ((csum >> 8) & 0xff) || *dp++ != ((csum >> 16) & 0xff) || *dp++ != ((csum >> 24) & 0xff))", " return FALSE;\n }\n else {\n csum ^= csum >> 16;\n", " if (*dp++ != (csum & 0xff) || *dp++ != ((csum >> 8) & 0xff))", " return FALSE;\n }", " checksum_passed++;\n }", " bcount -= meta_bc;\n dp += meta_bc;\n }", " return (bcount == 0) && (!verify_checksum || !(wphdr->flags & HAS_CHECKSUM) || checksum_passed);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1773, "char_start": 1770, "chars": "[1]" }, { "char_end": 1806, "char_start": 1803, "chars": "[2]" }, { "char_end": 1840, "char_start": 1837, "chars": "[3]" }, { "char_end": 2020, "char_start": 2017, "chars": "[1]" } ], "deleted": [ { "char_end": 1749, "char_start": 1747, "chars": "++" }, { "char_end": 1771, "char_start": 1770, "chars": "*" }, { "char_end": 1775, "char_start": 1773, "chars": "++" }, { "char_end": 1804, "char_start": 1803, "chars": "*" }, { "char_end": 1808, "char_start": 1806, "chars": "++" }, { "char_end": 1838, "char_start": 1837, "chars": "*" }, { "char_end": 1842, "char_start": 1840, "chars": "++" }, { "char_end": 1998, "char_start": 1996, "chars": "++" }, { "char_end": 2020, "char_start": 2019, "chars": "*" }, { "char_end": 2024, "char_start": 2022, "chars": "++" } ] }, "commit_link": "github.com/dbry/WavPack/commit/bba5389dc598a92bdf2b297c3ea34620b6679b5b", "file_name": "src/open_utils.c", "func_name": "WavpackVerifySingleBlock", "line_changes": { "added": [ { "char_end": 1867, "char_start": 1724, "line": " if (*dp != (csum & 0xff) || dp[1] != ((csum >> 8) & 0xff) || dp[2] != ((csum >> 16) & 0xff) || dp[3] != ((csum >> 24) & 0xff))\n", "line_no": 60 }, { "char_end": 2046, "char_start": 1971, "line": " if (*dp != (csum & 0xff) || dp[1] != ((csum >> 8) & 0xff))\n", "line_no": 66 } ], "deleted": [ { "char_end": 1869, "char_start": 1724, "line": " if (*dp++ != (csum & 0xff) || *dp++ != ((csum >> 8) & 0xff) || *dp++ != ((csum >> 16) & 0xff) || *dp++ != ((csum >> 24) & 0xff))\n", "line_no": 60 }, { "char_end": 2050, "char_start": 1973, "line": " if (*dp++ != (csum & 0xff) || *dp++ != ((csum >> 8) & 0xff))\n", "line_no": 66 } ] }, "vul_type": "cwe-125" }
452
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "int WavpackVerifySingleBlock (unsigned char *buffer, int verify_checksum)\n{\n WavpackHeader *wphdr = (WavpackHeader *) buffer;\n uint32_t checksum_passed = 0, bcount, meta_bc;\n unsigned char *dp, meta_id, c1, c2;", " if (strncmp (wphdr->ckID, \"wvpk\", 4) || wphdr->ckSize + 8 < sizeof (WavpackHeader))\n return FALSE;", " bcount = wphdr->ckSize - sizeof (WavpackHeader) + 8;\n dp = (unsigned char *)(wphdr + 1);", " while (bcount >= 2) {\n meta_id = *dp++;\n c1 = *dp++;", " meta_bc = c1 << 1;\n bcount -= 2;", " if (meta_id & ID_LARGE) {\n if (bcount < 2)\n return FALSE;", " c1 = *dp++;\n c2 = *dp++;\n meta_bc += ((uint32_t) c1 << 9) + ((uint32_t) c2 << 17);\n bcount -= 2;\n }", " if (bcount < meta_bc)\n return FALSE;", " if (verify_checksum && (meta_id & ID_UNIQUE) == ID_BLOCK_CHECKSUM) {\n#ifdef BITSTREAM_SHORTS\n uint16_t *csptr = (uint16_t*) buffer;\n#else\n unsigned char *csptr = buffer;\n#endif\n int wcount = (int)(dp - 2 - buffer) >> 1;\n uint32_t csum = (uint32_t) -1;", " if ((meta_id & ID_ODD_SIZE) || meta_bc < 2 || meta_bc > 4)\n return FALSE;", "#ifdef BITSTREAM_SHORTS\n while (wcount--)\n csum = (csum * 3) + *csptr++;\n#else\n WavpackNativeToLittleEndian ((WavpackHeader *) buffer, WavpackHeaderFormat);", " while (wcount--) {\n csum = (csum * 3) + csptr [0] + (csptr [1] << 8);\n csptr += 2;\n }", " WavpackLittleEndianToNative ((WavpackHeader *) buffer, WavpackHeaderFormat);\n#endif", " if (meta_bc == 4) {", " if (*dp != (csum & 0xff) || dp[1] != ((csum >> 8) & 0xff) || dp[2] != ((csum >> 16) & 0xff) || dp[3] != ((csum >> 24) & 0xff))", " return FALSE;\n }\n else {\n csum ^= csum >> 16;\n", " if (*dp != (csum & 0xff) || dp[1] != ((csum >> 8) & 0xff))", " return FALSE;\n }", " checksum_passed++;\n }", " bcount -= meta_bc;\n dp += meta_bc;\n }", " return (bcount == 0) && (!verify_checksum || !(wphdr->flags & HAS_CHECKSUM) || checksum_passed);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1773, "char_start": 1770, "chars": "[1]" }, { "char_end": 1806, "char_start": 1803, "chars": "[2]" }, { "char_end": 1840, "char_start": 1837, "chars": "[3]" }, { "char_end": 2020, "char_start": 2017, "chars": "[1]" } ], "deleted": [ { "char_end": 1749, "char_start": 1747, "chars": "++" }, { "char_end": 1771, "char_start": 1770, "chars": "*" }, { "char_end": 1775, "char_start": 1773, "chars": "++" }, { "char_end": 1804, "char_start": 1803, "chars": "*" }, { "char_end": 1808, "char_start": 1806, "chars": "++" }, { "char_end": 1838, "char_start": 1837, "chars": "*" }, { "char_end": 1842, "char_start": 1840, "chars": "++" }, { "char_end": 1998, "char_start": 1996, "chars": "++" }, { "char_end": 2020, "char_start": 2019, "chars": "*" }, { "char_end": 2024, "char_start": 2022, "chars": "++" } ] }, "commit_link": "github.com/dbry/WavPack/commit/bba5389dc598a92bdf2b297c3ea34620b6679b5b", "file_name": "src/open_utils.c", "func_name": "WavpackVerifySingleBlock", "line_changes": { "added": [ { "char_end": 1867, "char_start": 1724, "line": " if (*dp != (csum & 0xff) || dp[1] != ((csum >> 8) & 0xff) || dp[2] != ((csum >> 16) & 0xff) || dp[3] != ((csum >> 24) & 0xff))\n", "line_no": 60 }, { "char_end": 2046, "char_start": 1971, "line": " if (*dp != (csum & 0xff) || dp[1] != ((csum >> 8) & 0xff))\n", "line_no": 66 } ], "deleted": [ { "char_end": 1869, "char_start": 1724, "line": " if (*dp++ != (csum & 0xff) || *dp++ != ((csum >> 8) & 0xff) || *dp++ != ((csum >> 16) & 0xff) || *dp++ != ((csum >> 24) & 0xff))\n", "line_no": 60 }, { "char_end": 2050, "char_start": 1973, "line": " if (*dp++ != (csum & 0xff) || *dp++ != ((csum >> 8) & 0xff))\n", "line_no": 66 } ] }, "vul_type": "cwe-125" }
452
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static Image *ReadVIFFImage(const ImageInfo *image_info,\n ExceptionInfo *exception)\n{\n#define VFF_CM_genericRGB 15\n#define VFF_CM_ntscRGB 1\n#define VFF_CM_NONE 0\n#define VFF_DEP_DECORDER 0x4\n#define VFF_DEP_NSORDER 0x8\n#define VFF_DES_RAW 0\n#define VFF_LOC_IMPLICIT 1\n#define VFF_MAPTYP_NONE 0\n#define VFF_MAPTYP_1_BYTE 1\n#define VFF_MAPTYP_2_BYTE 2\n#define VFF_MAPTYP_4_BYTE 4\n#define VFF_MAPTYP_FLOAT 5\n#define VFF_MAPTYP_DOUBLE 7\n#define VFF_MS_NONE 0\n#define VFF_MS_ONEPERBAND 1\n#define VFF_MS_SHARED 3\n#define VFF_TYP_BIT 0\n#define VFF_TYP_1_BYTE 1\n#define VFF_TYP_2_BYTE 2\n#define VFF_TYP_4_BYTE 4\n#define VFF_TYP_FLOAT 5\n#define VFF_TYP_DOUBLE 9", " typedef struct _ViffInfo\n {\n unsigned char\n identifier,\n file_type,\n release,\n version,\n machine_dependency,\n reserve[3];", " char\n comment[512];", " unsigned int\n rows,\n columns,\n subrows;", " int\n x_offset,\n y_offset;", " float\n x_bits_per_pixel,\n y_bits_per_pixel;", " unsigned int\n location_type,\n location_dimension,\n number_of_images,\n number_data_bands,\n data_storage_type,\n data_encode_scheme,\n map_scheme,\n map_storage_type,\n map_rows,\n map_columns,\n map_subrows,\n map_enable,\n maps_per_cycle,\n color_space_model;\n } ViffInfo;", " double\n min_value,\n scale_factor,\n value;", " Image\n *image;", " int\n bit;", " MagickBooleanType\n status;", " MagickSizeType\n number_pixels;", " register IndexPacket\n *indexes;", " register ssize_t\n x;", " register PixelPacket\n *q;", " register ssize_t\n i;", " register unsigned char\n *p;", " size_t\n bytes_per_pixel,\n max_packets,\n quantum;", " ssize_t\n count,\n y;", " unsigned char\n *pixels;", " unsigned long\n lsb_first;", " ViffInfo\n viff_info;", " /*\n Open image file.\n */\n assert(image_info != (const ImageInfo *) NULL);\n assert(image_info->signature == MagickSignature);\n if (image_info->debug != MagickFalse)\n (void) LogMagickEvent(TraceEvent,GetMagickModule(),\"%s\",\n image_info->filename);\n assert(exception != (ExceptionInfo *) NULL);\n assert(exception->signature == MagickSignature);\n image=AcquireImage(image_info);\n status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);\n if (status == MagickFalse)\n {\n image=DestroyImageList(image);\n return((Image *) NULL);\n }\n /*\n Read VIFF header (1024 bytes).\n */\n count=ReadBlob(image,1,&viff_info.identifier);\n do\n {\n /*\n Verify VIFF identifier.\n */\n if ((count != 1) || ((unsigned char) viff_info.identifier != 0xab))\n ThrowReaderException(CorruptImageError,\"NotAVIFFImage\");\n /*\n Initialize VIFF image.\n */\n (void) ReadBlob(image,sizeof(viff_info.file_type),&viff_info.file_type);\n (void) ReadBlob(image,sizeof(viff_info.release),&viff_info.release);\n (void) ReadBlob(image,sizeof(viff_info.version),&viff_info.version);\n (void) ReadBlob(image,sizeof(viff_info.machine_dependency),\n &viff_info.machine_dependency);\n (void) ReadBlob(image,sizeof(viff_info.reserve),viff_info.reserve);\n (void) ReadBlob(image,512,(unsigned char *) viff_info.comment);\n viff_info.comment[511]='\\0';\n if (strlen(viff_info.comment) > 4)\n (void) SetImageProperty(image,\"comment\",viff_info.comment);\n if ((viff_info.machine_dependency == VFF_DEP_DECORDER) ||\n (viff_info.machine_dependency == VFF_DEP_NSORDER))\n image->endian=LSBEndian;\n else\n image->endian=MSBEndian;\n viff_info.rows=ReadBlobLong(image);\n viff_info.columns=ReadBlobLong(image);\n viff_info.subrows=ReadBlobLong(image);\n viff_info.x_offset=(int) ReadBlobLong(image);\n viff_info.y_offset=(int) ReadBlobLong(image);\n viff_info.x_bits_per_pixel=(float) ReadBlobLong(image);\n viff_info.y_bits_per_pixel=(float) ReadBlobLong(image);\n viff_info.location_type=ReadBlobLong(image);\n viff_info.location_dimension=ReadBlobLong(image);\n viff_info.number_of_images=ReadBlobLong(image);\n viff_info.number_data_bands=ReadBlobLong(image);\n viff_info.data_storage_type=ReadBlobLong(image);\n viff_info.data_encode_scheme=ReadBlobLong(image);\n viff_info.map_scheme=ReadBlobLong(image);\n viff_info.map_storage_type=ReadBlobLong(image);\n viff_info.map_rows=ReadBlobLong(image);\n viff_info.map_columns=ReadBlobLong(image);\n viff_info.map_subrows=ReadBlobLong(image);\n viff_info.map_enable=ReadBlobLong(image);\n viff_info.maps_per_cycle=ReadBlobLong(image);\n viff_info.color_space_model=ReadBlobLong(image);\n for (i=0; i < 420; i++)\n (void) ReadBlobByte(image);\n if (EOFBlob(image) != MagickFalse)\n ThrowReaderException(CorruptImageError,\"UnexpectedEndOfFile\");\n image->columns=viff_info.rows;\n image->rows=viff_info.columns;\n image->depth=viff_info.x_bits_per_pixel <= 8 ? 8UL :\n MAGICKCORE_QUANTUM_DEPTH;\n /*\n Verify that we can read this VIFF image.\n */\n number_pixels=(MagickSizeType) viff_info.columns*viff_info.rows;\n if (number_pixels != (size_t) number_pixels)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n if (number_pixels == 0)\n ThrowReaderException(CoderError,\"ImageColumnOrRowSizeIsNotSupported\");\n if ((viff_info.number_data_bands < 1) || (viff_info.number_data_bands > 4))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n if ((viff_info.data_storage_type != VFF_TYP_BIT) &&\n (viff_info.data_storage_type != VFF_TYP_1_BYTE) &&\n (viff_info.data_storage_type != VFF_TYP_2_BYTE) &&\n (viff_info.data_storage_type != VFF_TYP_4_BYTE) &&\n (viff_info.data_storage_type != VFF_TYP_FLOAT) &&\n (viff_info.data_storage_type != VFF_TYP_DOUBLE))\n ThrowReaderException(CoderError,\"DataStorageTypeIsNotSupported\");\n if (viff_info.data_encode_scheme != VFF_DES_RAW)\n ThrowReaderException(CoderError,\"DataEncodingSchemeIsNotSupported\");\n if ((viff_info.map_storage_type != VFF_MAPTYP_NONE) &&\n (viff_info.map_storage_type != VFF_MAPTYP_1_BYTE) &&\n (viff_info.map_storage_type != VFF_MAPTYP_2_BYTE) &&\n (viff_info.map_storage_type != VFF_MAPTYP_4_BYTE) &&\n (viff_info.map_storage_type != VFF_MAPTYP_FLOAT) &&\n (viff_info.map_storage_type != VFF_MAPTYP_DOUBLE))\n ThrowReaderException(CoderError,\"MapStorageTypeIsNotSupported\");\n if ((viff_info.color_space_model != VFF_CM_NONE) &&\n (viff_info.color_space_model != VFF_CM_ntscRGB) &&\n (viff_info.color_space_model != VFF_CM_genericRGB))\n ThrowReaderException(CoderError,\"ColorspaceModelIsNotSupported\");\n if (viff_info.location_type != VFF_LOC_IMPLICIT)\n ThrowReaderException(CoderError,\"LocationTypeIsNotSupported\");\n if (viff_info.number_of_images != 1)\n ThrowReaderException(CoderError,\"NumberOfImagesIsNotSupported\");\n if (viff_info.map_rows == 0)\n viff_info.map_scheme=VFF_MS_NONE;\n switch ((int) viff_info.map_scheme)\n {\n case VFF_MS_NONE:\n {\n if (viff_info.number_data_bands < 3)\n {\n /*\n Create linear color ramp.\n */\n if (viff_info.data_storage_type == VFF_TYP_BIT)\n image->colors=2;\n else\n if (viff_info.data_storage_type == VFF_MAPTYP_1_BYTE)\n image->colors=256UL;\n else\n image->colors=image->depth <= 8 ? 256UL : 65536UL;\n if (AcquireImageColormap(image,image->colors) == MagickFalse)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n }\n break;\n }\n case VFF_MS_ONEPERBAND:\n case VFF_MS_SHARED:\n {\n unsigned char\n *viff_colormap;", " /*\n Allocate VIFF colormap.\n */\n switch ((int) viff_info.map_storage_type)\n {\n case VFF_MAPTYP_1_BYTE: bytes_per_pixel=1; break;\n case VFF_MAPTYP_2_BYTE: bytes_per_pixel=2; break;\n case VFF_MAPTYP_4_BYTE: bytes_per_pixel=4; break;\n case VFF_MAPTYP_FLOAT: bytes_per_pixel=4; break;\n case VFF_MAPTYP_DOUBLE: bytes_per_pixel=8; break;\n default: bytes_per_pixel=1; break;\n }\n image->colors=viff_info.map_columns;\n if (AcquireImageColormap(image,image->colors) == MagickFalse)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n if (viff_info.map_rows >\n (viff_info.map_rows*bytes_per_pixel*sizeof(*viff_colormap)))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n viff_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,\n viff_info.map_rows*bytes_per_pixel*sizeof(*viff_colormap));\n if (viff_colormap == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n /*\n Read VIFF raster colormap.\n */\n (void) ReadBlob(image,bytes_per_pixel*image->colors*viff_info.map_rows,\n viff_colormap);\n lsb_first=1;\n if (*(char *) &lsb_first &&\n ((viff_info.machine_dependency != VFF_DEP_DECORDER) &&\n (viff_info.machine_dependency != VFF_DEP_NSORDER)))\n switch ((int) viff_info.map_storage_type)\n {\n case VFF_MAPTYP_2_BYTE:\n {\n MSBOrderShort(viff_colormap,(bytes_per_pixel*image->colors*\n viff_info.map_rows));\n break;\n }\n case VFF_MAPTYP_4_BYTE:\n case VFF_MAPTYP_FLOAT:\n {\n MSBOrderLong(viff_colormap,(bytes_per_pixel*image->colors*\n viff_info.map_rows));\n break;\n }\n default: break;\n }\n for (i=0; i < (ssize_t) (viff_info.map_rows*image->colors); i++)\n {\n switch ((int) viff_info.map_storage_type)\n {\n case VFF_MAPTYP_2_BYTE: value=1.0*((short *) viff_colormap)[i]; break;\n case VFF_MAPTYP_4_BYTE: value=1.0*((int *) viff_colormap)[i]; break;\n case VFF_MAPTYP_FLOAT: value=((float *) viff_colormap)[i]; break;\n case VFF_MAPTYP_DOUBLE: value=((double *) viff_colormap)[i]; break;\n default: value=1.0*viff_colormap[i]; break;\n }\n if (i < (ssize_t) image->colors)\n {\n image->colormap[i].red=ScaleCharToQuantum((unsigned char) value);\n image->colormap[i].green=ScaleCharToQuantum((unsigned char)\n value);\n image->colormap[i].blue=ScaleCharToQuantum((unsigned char) value);\n }\n else\n if (i < (ssize_t) (2*image->colors))\n image->colormap[i % image->colors].green=ScaleCharToQuantum(\n (unsigned char) value);\n else\n if (i < (ssize_t) (3*image->colors))\n image->colormap[i % image->colors].blue=ScaleCharToQuantum(\n (unsigned char) value);\n }\n viff_colormap=(unsigned char *) RelinquishMagickMemory(viff_colormap);\n break;\n }\n default:\n ThrowReaderException(CoderError,\"ColormapTypeNotSupported\");\n }\n /*\n Initialize image structure.\n */\n image->matte=viff_info.number_data_bands == 4 ? MagickTrue : MagickFalse;\n image->storage_class=\n (viff_info.number_data_bands < 3 ? PseudoClass : DirectClass);\n image->columns=viff_info.rows;\n image->rows=viff_info.columns;\n if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))\n if (image->scene >= (image_info->scene+image_info->number_scenes-1))\n break;\n status=SetImageExtent(image,image->columns,image->rows);\n if (status == MagickFalse)\n {\n InheritException(exception,&image->exception);\n return(DestroyImageList(image));\n }\n /*\n Allocate VIFF pixels.\n */\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE: bytes_per_pixel=2; break;\n case VFF_TYP_4_BYTE: bytes_per_pixel=4; break;\n case VFF_TYP_FLOAT: bytes_per_pixel=4; break;\n case VFF_TYP_DOUBLE: bytes_per_pixel=8; break;\n default: bytes_per_pixel=1; break;\n }\n if (viff_info.data_storage_type == VFF_TYP_BIT)\n max_packets=((image->columns+7UL) >> 3UL)*image->rows;\n else\n max_packets=(size_t) (number_pixels*viff_info.number_data_bands);", " pixels=(unsigned char *) AcquireQuantumMemory(max_packets,\n bytes_per_pixel*sizeof(*pixels));", " if (pixels == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n (void) ReadBlob(image,bytes_per_pixel*max_packets,pixels);\n lsb_first=1;\n if (*(char *) &lsb_first &&\n ((viff_info.machine_dependency != VFF_DEP_DECORDER) &&\n (viff_info.machine_dependency != VFF_DEP_NSORDER)))\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE:\n {\n MSBOrderShort(pixels,bytes_per_pixel*max_packets);\n break;\n }\n case VFF_TYP_4_BYTE:\n case VFF_TYP_FLOAT:\n {\n MSBOrderLong(pixels,bytes_per_pixel*max_packets);\n break;\n }\n default: break;\n }\n min_value=0.0;\n scale_factor=1.0;\n if ((viff_info.data_storage_type != VFF_TYP_1_BYTE) &&\n (viff_info.map_scheme == VFF_MS_NONE))\n {\n double\n max_value;", " /*\n Determine scale factor.\n */\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE: value=1.0*((short *) pixels)[0]; break;\n case VFF_TYP_4_BYTE: value=1.0*((int *) pixels)[0]; break;\n case VFF_TYP_FLOAT: value=((float *) pixels)[0]; break;\n case VFF_TYP_DOUBLE: value=((double *) pixels)[0]; break;\n default: value=1.0*pixels[0]; break;\n }\n max_value=value;\n min_value=value;\n for (i=0; i < (ssize_t) max_packets; i++)\n {\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE: value=1.0*((short *) pixels)[i]; break;\n case VFF_TYP_4_BYTE: value=1.0*((int *) pixels)[i]; break;\n case VFF_TYP_FLOAT: value=((float *) pixels)[i]; break;\n case VFF_TYP_DOUBLE: value=((double *) pixels)[i]; break;\n default: value=1.0*pixels[i]; break;\n }\n if (value > max_value)\n max_value=value;\n else\n if (value < min_value)\n min_value=value;\n }\n if ((min_value == 0) && (max_value == 0))\n scale_factor=0;\n else\n if (min_value == max_value)\n {\n scale_factor=(MagickRealType) QuantumRange/min_value;\n min_value=0;\n }\n else\n scale_factor=(MagickRealType) QuantumRange/(max_value-min_value);\n }\n /*\n Convert pixels to Quantum size.\n */\n p=(unsigned char *) pixels;\n for (i=0; i < (ssize_t) max_packets; i++)\n {\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE: value=1.0*((short *) pixels)[i]; break;\n case VFF_TYP_4_BYTE: value=1.0*((int *) pixels)[i]; break;\n case VFF_TYP_FLOAT: value=((float *) pixels)[i]; break;\n case VFF_TYP_DOUBLE: value=((double *) pixels)[i]; break;\n default: value=1.0*pixels[i]; break;\n }\n if (viff_info.map_scheme == VFF_MS_NONE)\n {\n value=(value-min_value)*scale_factor;\n if (value > QuantumRange)\n value=QuantumRange;\n else\n if (value < 0)\n value=0;\n }\n *p=(unsigned char) ((Quantum) value);\n p++;\n }\n /*\n Convert VIFF raster image to pixel packets.\n */\n p=(unsigned char *) pixels;\n if (viff_info.data_storage_type == VFF_TYP_BIT)\n {\n /*\n Convert bitmap scanline.\n */\n if (image->storage_class != PseudoClass)\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);\n if (q == (PixelPacket *) NULL)\n break;\n indexes=GetAuthenticIndexQueue(image);\n for (x=0; x < (ssize_t) (image->columns-7); x+=8)\n {\n for (bit=0; bit < 8; bit++)\n {\n quantum=(size_t) ((*p) & (0x01 << bit) ? 0 : 1);\n SetPixelRed(q,quantum == 0 ? 0 : QuantumRange);\n SetPixelGreen(q,quantum == 0 ? 0 : QuantumRange);\n SetPixelBlue(q,quantum == 0 ? 0 : QuantumRange);\n if (image->storage_class == PseudoClass)\n SetPixelIndex(indexes+x+bit,quantum);\n }\n p++;\n }\n if ((image->columns % 8) != 0)\n {\n for (bit=0; bit < (int) (image->columns % 8); bit++)\n {\n quantum=(size_t) ((*p) & (0x01 << bit) ? 0 : 1);\n SetPixelRed(q,quantum == 0 ? 0 : QuantumRange);\n SetPixelGreen(q,quantum == 0 ? 0 : QuantumRange);\n SetPixelBlue(q,quantum == 0 ? 0 : QuantumRange);\n if (image->storage_class == PseudoClass)\n SetPixelIndex(indexes+x+bit,quantum);\n }\n p++;\n }\n if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n }\n else\n if (image->storage_class == PseudoClass)\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);\n if (q == (PixelPacket *) NULL)\n break;\n indexes=GetAuthenticIndexQueue(image);\n for (x=0; x < (ssize_t) image->columns; x++)\n SetPixelIndex(indexes+x,*p++);\n if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n else\n {\n /*\n Convert DirectColor scanline.\n */\n number_pixels=(MagickSizeType) image->columns*image->rows;\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);\n if (q == (PixelPacket *) NULL)\n break;\n for (x=0; x < (ssize_t) image->columns; x++)\n {\n SetPixelRed(q,ScaleCharToQuantum(*p));\n SetPixelGreen(q,ScaleCharToQuantum(*(p+number_pixels)));\n SetPixelBlue(q,ScaleCharToQuantum(*(p+2*number_pixels)));\n if (image->colors != 0)\n {\n ssize_t\n index;", " index=(ssize_t) GetPixelRed(q);\n SetPixelRed(q,image->colormap[(ssize_t)\n ConstrainColormapIndex(image,index)].red);\n index=(ssize_t) GetPixelGreen(q);\n SetPixelGreen(q,image->colormap[(ssize_t)\n ConstrainColormapIndex(image,index)].green);\n index=(ssize_t) GetPixelRed(q);\n SetPixelBlue(q,image->colormap[(ssize_t)\n ConstrainColormapIndex(image,index)].blue);\n }\n SetPixelOpacity(q,image->matte != MagickFalse ? QuantumRange-\n ScaleCharToQuantum(*(p+number_pixels*3)) : OpaqueOpacity);\n p++;\n q++;\n }\n if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n }\n pixels=(unsigned char *) RelinquishMagickMemory(pixels);\n if (image->storage_class == PseudoClass)\n (void) SyncImage(image);\n if (EOFBlob(image) != MagickFalse)\n {\n ThrowFileException(exception,CorruptImageError,\"UnexpectedEndOfFile\",\n image->filename);\n break;\n }\n /*\n Proceed to next image.\n */\n if (image_info->number_scenes != 0)\n if (image->scene >= (image_info->scene+image_info->number_scenes-1))\n break;\n count=ReadBlob(image,1,&viff_info.identifier);\n if ((count != 0) && (viff_info.identifier == 0xab))\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);\n if (GetNextImageInList(image) == (Image *) NULL)\n {\n image=DestroyImageList(image);\n return((Image *) NULL);\n }\n image=SyncNextImageInList(image);\n status=SetImageProgress(image,LoadImagesTag,TellBlob(image),\n GetBlobSize(image));\n if (status == MagickFalse)\n break;\n }\n } while ((count != 0) && (viff_info.identifier == 0xab));\n (void) CloseBlob(image);\n return(GetFirstImageInList(image));\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 12480, "char_start": 12473, "chars": "MagickM" }, { "char_end": 12489, "char_start": 12482, "chars": "(number" }, { "char_end": 12493, "char_start": 12491, "chars": "ix" }, { "char_end": 12495, "char_start": 12494, "chars": "l" }, { "char_end": 12517, "char_start": 12504, "chars": "max_packets)," } ], "deleted": [ { "char_end": 12474, "char_start": 12473, "chars": "m" }, { "char_end": 12481, "char_start": 12478, "chars": "ack" }, { "char_end": 12483, "char_start": 12482, "chars": "t" } ] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/ca0c886abd6d3ef335eb74150cd23b89ebd17135", "file_name": "coders/viff.c", "func_name": "ReadVIFFImage", "line_changes": { "added": [ { "char_end": 12498, "char_start": 12423, "line": " pixels=(unsigned char *) AcquireQuantumMemory(MagickMax(number_pixels,\n", "line_no": 370 }, { "char_end": 12551, "char_start": 12498, "line": " max_packets),bytes_per_pixel*sizeof(*pixels));\n", "line_no": 371 } ], "deleted": [ { "char_end": 12486, "char_start": 12423, "line": " pixels=(unsigned char *) AcquireQuantumMemory(max_packets,\n", "line_no": 370 }, { "char_end": 12526, "char_start": 12486, "line": " bytes_per_pixel*sizeof(*pixels));\n", "line_no": 371 } ] }, "vul_type": "cwe-125" }
453
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static Image *ReadVIFFImage(const ImageInfo *image_info,\n ExceptionInfo *exception)\n{\n#define VFF_CM_genericRGB 15\n#define VFF_CM_ntscRGB 1\n#define VFF_CM_NONE 0\n#define VFF_DEP_DECORDER 0x4\n#define VFF_DEP_NSORDER 0x8\n#define VFF_DES_RAW 0\n#define VFF_LOC_IMPLICIT 1\n#define VFF_MAPTYP_NONE 0\n#define VFF_MAPTYP_1_BYTE 1\n#define VFF_MAPTYP_2_BYTE 2\n#define VFF_MAPTYP_4_BYTE 4\n#define VFF_MAPTYP_FLOAT 5\n#define VFF_MAPTYP_DOUBLE 7\n#define VFF_MS_NONE 0\n#define VFF_MS_ONEPERBAND 1\n#define VFF_MS_SHARED 3\n#define VFF_TYP_BIT 0\n#define VFF_TYP_1_BYTE 1\n#define VFF_TYP_2_BYTE 2\n#define VFF_TYP_4_BYTE 4\n#define VFF_TYP_FLOAT 5\n#define VFF_TYP_DOUBLE 9", " typedef struct _ViffInfo\n {\n unsigned char\n identifier,\n file_type,\n release,\n version,\n machine_dependency,\n reserve[3];", " char\n comment[512];", " unsigned int\n rows,\n columns,\n subrows;", " int\n x_offset,\n y_offset;", " float\n x_bits_per_pixel,\n y_bits_per_pixel;", " unsigned int\n location_type,\n location_dimension,\n number_of_images,\n number_data_bands,\n data_storage_type,\n data_encode_scheme,\n map_scheme,\n map_storage_type,\n map_rows,\n map_columns,\n map_subrows,\n map_enable,\n maps_per_cycle,\n color_space_model;\n } ViffInfo;", " double\n min_value,\n scale_factor,\n value;", " Image\n *image;", " int\n bit;", " MagickBooleanType\n status;", " MagickSizeType\n number_pixels;", " register IndexPacket\n *indexes;", " register ssize_t\n x;", " register PixelPacket\n *q;", " register ssize_t\n i;", " register unsigned char\n *p;", " size_t\n bytes_per_pixel,\n max_packets,\n quantum;", " ssize_t\n count,\n y;", " unsigned char\n *pixels;", " unsigned long\n lsb_first;", " ViffInfo\n viff_info;", " /*\n Open image file.\n */\n assert(image_info != (const ImageInfo *) NULL);\n assert(image_info->signature == MagickSignature);\n if (image_info->debug != MagickFalse)\n (void) LogMagickEvent(TraceEvent,GetMagickModule(),\"%s\",\n image_info->filename);\n assert(exception != (ExceptionInfo *) NULL);\n assert(exception->signature == MagickSignature);\n image=AcquireImage(image_info);\n status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);\n if (status == MagickFalse)\n {\n image=DestroyImageList(image);\n return((Image *) NULL);\n }\n /*\n Read VIFF header (1024 bytes).\n */\n count=ReadBlob(image,1,&viff_info.identifier);\n do\n {\n /*\n Verify VIFF identifier.\n */\n if ((count != 1) || ((unsigned char) viff_info.identifier != 0xab))\n ThrowReaderException(CorruptImageError,\"NotAVIFFImage\");\n /*\n Initialize VIFF image.\n */\n (void) ReadBlob(image,sizeof(viff_info.file_type),&viff_info.file_type);\n (void) ReadBlob(image,sizeof(viff_info.release),&viff_info.release);\n (void) ReadBlob(image,sizeof(viff_info.version),&viff_info.version);\n (void) ReadBlob(image,sizeof(viff_info.machine_dependency),\n &viff_info.machine_dependency);\n (void) ReadBlob(image,sizeof(viff_info.reserve),viff_info.reserve);\n (void) ReadBlob(image,512,(unsigned char *) viff_info.comment);\n viff_info.comment[511]='\\0';\n if (strlen(viff_info.comment) > 4)\n (void) SetImageProperty(image,\"comment\",viff_info.comment);\n if ((viff_info.machine_dependency == VFF_DEP_DECORDER) ||\n (viff_info.machine_dependency == VFF_DEP_NSORDER))\n image->endian=LSBEndian;\n else\n image->endian=MSBEndian;\n viff_info.rows=ReadBlobLong(image);\n viff_info.columns=ReadBlobLong(image);\n viff_info.subrows=ReadBlobLong(image);\n viff_info.x_offset=(int) ReadBlobLong(image);\n viff_info.y_offset=(int) ReadBlobLong(image);\n viff_info.x_bits_per_pixel=(float) ReadBlobLong(image);\n viff_info.y_bits_per_pixel=(float) ReadBlobLong(image);\n viff_info.location_type=ReadBlobLong(image);\n viff_info.location_dimension=ReadBlobLong(image);\n viff_info.number_of_images=ReadBlobLong(image);\n viff_info.number_data_bands=ReadBlobLong(image);\n viff_info.data_storage_type=ReadBlobLong(image);\n viff_info.data_encode_scheme=ReadBlobLong(image);\n viff_info.map_scheme=ReadBlobLong(image);\n viff_info.map_storage_type=ReadBlobLong(image);\n viff_info.map_rows=ReadBlobLong(image);\n viff_info.map_columns=ReadBlobLong(image);\n viff_info.map_subrows=ReadBlobLong(image);\n viff_info.map_enable=ReadBlobLong(image);\n viff_info.maps_per_cycle=ReadBlobLong(image);\n viff_info.color_space_model=ReadBlobLong(image);\n for (i=0; i < 420; i++)\n (void) ReadBlobByte(image);\n if (EOFBlob(image) != MagickFalse)\n ThrowReaderException(CorruptImageError,\"UnexpectedEndOfFile\");\n image->columns=viff_info.rows;\n image->rows=viff_info.columns;\n image->depth=viff_info.x_bits_per_pixel <= 8 ? 8UL :\n MAGICKCORE_QUANTUM_DEPTH;\n /*\n Verify that we can read this VIFF image.\n */\n number_pixels=(MagickSizeType) viff_info.columns*viff_info.rows;\n if (number_pixels != (size_t) number_pixels)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n if (number_pixels == 0)\n ThrowReaderException(CoderError,\"ImageColumnOrRowSizeIsNotSupported\");\n if ((viff_info.number_data_bands < 1) || (viff_info.number_data_bands > 4))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n if ((viff_info.data_storage_type != VFF_TYP_BIT) &&\n (viff_info.data_storage_type != VFF_TYP_1_BYTE) &&\n (viff_info.data_storage_type != VFF_TYP_2_BYTE) &&\n (viff_info.data_storage_type != VFF_TYP_4_BYTE) &&\n (viff_info.data_storage_type != VFF_TYP_FLOAT) &&\n (viff_info.data_storage_type != VFF_TYP_DOUBLE))\n ThrowReaderException(CoderError,\"DataStorageTypeIsNotSupported\");\n if (viff_info.data_encode_scheme != VFF_DES_RAW)\n ThrowReaderException(CoderError,\"DataEncodingSchemeIsNotSupported\");\n if ((viff_info.map_storage_type != VFF_MAPTYP_NONE) &&\n (viff_info.map_storage_type != VFF_MAPTYP_1_BYTE) &&\n (viff_info.map_storage_type != VFF_MAPTYP_2_BYTE) &&\n (viff_info.map_storage_type != VFF_MAPTYP_4_BYTE) &&\n (viff_info.map_storage_type != VFF_MAPTYP_FLOAT) &&\n (viff_info.map_storage_type != VFF_MAPTYP_DOUBLE))\n ThrowReaderException(CoderError,\"MapStorageTypeIsNotSupported\");\n if ((viff_info.color_space_model != VFF_CM_NONE) &&\n (viff_info.color_space_model != VFF_CM_ntscRGB) &&\n (viff_info.color_space_model != VFF_CM_genericRGB))\n ThrowReaderException(CoderError,\"ColorspaceModelIsNotSupported\");\n if (viff_info.location_type != VFF_LOC_IMPLICIT)\n ThrowReaderException(CoderError,\"LocationTypeIsNotSupported\");\n if (viff_info.number_of_images != 1)\n ThrowReaderException(CoderError,\"NumberOfImagesIsNotSupported\");\n if (viff_info.map_rows == 0)\n viff_info.map_scheme=VFF_MS_NONE;\n switch ((int) viff_info.map_scheme)\n {\n case VFF_MS_NONE:\n {\n if (viff_info.number_data_bands < 3)\n {\n /*\n Create linear color ramp.\n */\n if (viff_info.data_storage_type == VFF_TYP_BIT)\n image->colors=2;\n else\n if (viff_info.data_storage_type == VFF_MAPTYP_1_BYTE)\n image->colors=256UL;\n else\n image->colors=image->depth <= 8 ? 256UL : 65536UL;\n if (AcquireImageColormap(image,image->colors) == MagickFalse)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n }\n break;\n }\n case VFF_MS_ONEPERBAND:\n case VFF_MS_SHARED:\n {\n unsigned char\n *viff_colormap;", " /*\n Allocate VIFF colormap.\n */\n switch ((int) viff_info.map_storage_type)\n {\n case VFF_MAPTYP_1_BYTE: bytes_per_pixel=1; break;\n case VFF_MAPTYP_2_BYTE: bytes_per_pixel=2; break;\n case VFF_MAPTYP_4_BYTE: bytes_per_pixel=4; break;\n case VFF_MAPTYP_FLOAT: bytes_per_pixel=4; break;\n case VFF_MAPTYP_DOUBLE: bytes_per_pixel=8; break;\n default: bytes_per_pixel=1; break;\n }\n image->colors=viff_info.map_columns;\n if (AcquireImageColormap(image,image->colors) == MagickFalse)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n if (viff_info.map_rows >\n (viff_info.map_rows*bytes_per_pixel*sizeof(*viff_colormap)))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n viff_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,\n viff_info.map_rows*bytes_per_pixel*sizeof(*viff_colormap));\n if (viff_colormap == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n /*\n Read VIFF raster colormap.\n */\n (void) ReadBlob(image,bytes_per_pixel*image->colors*viff_info.map_rows,\n viff_colormap);\n lsb_first=1;\n if (*(char *) &lsb_first &&\n ((viff_info.machine_dependency != VFF_DEP_DECORDER) &&\n (viff_info.machine_dependency != VFF_DEP_NSORDER)))\n switch ((int) viff_info.map_storage_type)\n {\n case VFF_MAPTYP_2_BYTE:\n {\n MSBOrderShort(viff_colormap,(bytes_per_pixel*image->colors*\n viff_info.map_rows));\n break;\n }\n case VFF_MAPTYP_4_BYTE:\n case VFF_MAPTYP_FLOAT:\n {\n MSBOrderLong(viff_colormap,(bytes_per_pixel*image->colors*\n viff_info.map_rows));\n break;\n }\n default: break;\n }\n for (i=0; i < (ssize_t) (viff_info.map_rows*image->colors); i++)\n {\n switch ((int) viff_info.map_storage_type)\n {\n case VFF_MAPTYP_2_BYTE: value=1.0*((short *) viff_colormap)[i]; break;\n case VFF_MAPTYP_4_BYTE: value=1.0*((int *) viff_colormap)[i]; break;\n case VFF_MAPTYP_FLOAT: value=((float *) viff_colormap)[i]; break;\n case VFF_MAPTYP_DOUBLE: value=((double *) viff_colormap)[i]; break;\n default: value=1.0*viff_colormap[i]; break;\n }\n if (i < (ssize_t) image->colors)\n {\n image->colormap[i].red=ScaleCharToQuantum((unsigned char) value);\n image->colormap[i].green=ScaleCharToQuantum((unsigned char)\n value);\n image->colormap[i].blue=ScaleCharToQuantum((unsigned char) value);\n }\n else\n if (i < (ssize_t) (2*image->colors))\n image->colormap[i % image->colors].green=ScaleCharToQuantum(\n (unsigned char) value);\n else\n if (i < (ssize_t) (3*image->colors))\n image->colormap[i % image->colors].blue=ScaleCharToQuantum(\n (unsigned char) value);\n }\n viff_colormap=(unsigned char *) RelinquishMagickMemory(viff_colormap);\n break;\n }\n default:\n ThrowReaderException(CoderError,\"ColormapTypeNotSupported\");\n }\n /*\n Initialize image structure.\n */\n image->matte=viff_info.number_data_bands == 4 ? MagickTrue : MagickFalse;\n image->storage_class=\n (viff_info.number_data_bands < 3 ? PseudoClass : DirectClass);\n image->columns=viff_info.rows;\n image->rows=viff_info.columns;\n if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))\n if (image->scene >= (image_info->scene+image_info->number_scenes-1))\n break;\n status=SetImageExtent(image,image->columns,image->rows);\n if (status == MagickFalse)\n {\n InheritException(exception,&image->exception);\n return(DestroyImageList(image));\n }\n /*\n Allocate VIFF pixels.\n */\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE: bytes_per_pixel=2; break;\n case VFF_TYP_4_BYTE: bytes_per_pixel=4; break;\n case VFF_TYP_FLOAT: bytes_per_pixel=4; break;\n case VFF_TYP_DOUBLE: bytes_per_pixel=8; break;\n default: bytes_per_pixel=1; break;\n }\n if (viff_info.data_storage_type == VFF_TYP_BIT)\n max_packets=((image->columns+7UL) >> 3UL)*image->rows;\n else\n max_packets=(size_t) (number_pixels*viff_info.number_data_bands);", " pixels=(unsigned char *) AcquireQuantumMemory(MagickMax(number_pixels,\n max_packets),bytes_per_pixel*sizeof(*pixels));", " if (pixels == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");\n (void) ReadBlob(image,bytes_per_pixel*max_packets,pixels);\n lsb_first=1;\n if (*(char *) &lsb_first &&\n ((viff_info.machine_dependency != VFF_DEP_DECORDER) &&\n (viff_info.machine_dependency != VFF_DEP_NSORDER)))\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE:\n {\n MSBOrderShort(pixels,bytes_per_pixel*max_packets);\n break;\n }\n case VFF_TYP_4_BYTE:\n case VFF_TYP_FLOAT:\n {\n MSBOrderLong(pixels,bytes_per_pixel*max_packets);\n break;\n }\n default: break;\n }\n min_value=0.0;\n scale_factor=1.0;\n if ((viff_info.data_storage_type != VFF_TYP_1_BYTE) &&\n (viff_info.map_scheme == VFF_MS_NONE))\n {\n double\n max_value;", " /*\n Determine scale factor.\n */\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE: value=1.0*((short *) pixels)[0]; break;\n case VFF_TYP_4_BYTE: value=1.0*((int *) pixels)[0]; break;\n case VFF_TYP_FLOAT: value=((float *) pixels)[0]; break;\n case VFF_TYP_DOUBLE: value=((double *) pixels)[0]; break;\n default: value=1.0*pixels[0]; break;\n }\n max_value=value;\n min_value=value;\n for (i=0; i < (ssize_t) max_packets; i++)\n {\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE: value=1.0*((short *) pixels)[i]; break;\n case VFF_TYP_4_BYTE: value=1.0*((int *) pixels)[i]; break;\n case VFF_TYP_FLOAT: value=((float *) pixels)[i]; break;\n case VFF_TYP_DOUBLE: value=((double *) pixels)[i]; break;\n default: value=1.0*pixels[i]; break;\n }\n if (value > max_value)\n max_value=value;\n else\n if (value < min_value)\n min_value=value;\n }\n if ((min_value == 0) && (max_value == 0))\n scale_factor=0;\n else\n if (min_value == max_value)\n {\n scale_factor=(MagickRealType) QuantumRange/min_value;\n min_value=0;\n }\n else\n scale_factor=(MagickRealType) QuantumRange/(max_value-min_value);\n }\n /*\n Convert pixels to Quantum size.\n */\n p=(unsigned char *) pixels;\n for (i=0; i < (ssize_t) max_packets; i++)\n {\n switch ((int) viff_info.data_storage_type)\n {\n case VFF_TYP_2_BYTE: value=1.0*((short *) pixels)[i]; break;\n case VFF_TYP_4_BYTE: value=1.0*((int *) pixels)[i]; break;\n case VFF_TYP_FLOAT: value=((float *) pixels)[i]; break;\n case VFF_TYP_DOUBLE: value=((double *) pixels)[i]; break;\n default: value=1.0*pixels[i]; break;\n }\n if (viff_info.map_scheme == VFF_MS_NONE)\n {\n value=(value-min_value)*scale_factor;\n if (value > QuantumRange)\n value=QuantumRange;\n else\n if (value < 0)\n value=0;\n }\n *p=(unsigned char) ((Quantum) value);\n p++;\n }\n /*\n Convert VIFF raster image to pixel packets.\n */\n p=(unsigned char *) pixels;\n if (viff_info.data_storage_type == VFF_TYP_BIT)\n {\n /*\n Convert bitmap scanline.\n */\n if (image->storage_class != PseudoClass)\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);\n if (q == (PixelPacket *) NULL)\n break;\n indexes=GetAuthenticIndexQueue(image);\n for (x=0; x < (ssize_t) (image->columns-7); x+=8)\n {\n for (bit=0; bit < 8; bit++)\n {\n quantum=(size_t) ((*p) & (0x01 << bit) ? 0 : 1);\n SetPixelRed(q,quantum == 0 ? 0 : QuantumRange);\n SetPixelGreen(q,quantum == 0 ? 0 : QuantumRange);\n SetPixelBlue(q,quantum == 0 ? 0 : QuantumRange);\n if (image->storage_class == PseudoClass)\n SetPixelIndex(indexes+x+bit,quantum);\n }\n p++;\n }\n if ((image->columns % 8) != 0)\n {\n for (bit=0; bit < (int) (image->columns % 8); bit++)\n {\n quantum=(size_t) ((*p) & (0x01 << bit) ? 0 : 1);\n SetPixelRed(q,quantum == 0 ? 0 : QuantumRange);\n SetPixelGreen(q,quantum == 0 ? 0 : QuantumRange);\n SetPixelBlue(q,quantum == 0 ? 0 : QuantumRange);\n if (image->storage_class == PseudoClass)\n SetPixelIndex(indexes+x+bit,quantum);\n }\n p++;\n }\n if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n }\n else\n if (image->storage_class == PseudoClass)\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);\n if (q == (PixelPacket *) NULL)\n break;\n indexes=GetAuthenticIndexQueue(image);\n for (x=0; x < (ssize_t) image->columns; x++)\n SetPixelIndex(indexes+x,*p++);\n if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n else\n {\n /*\n Convert DirectColor scanline.\n */\n number_pixels=(MagickSizeType) image->columns*image->rows;\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);\n if (q == (PixelPacket *) NULL)\n break;\n for (x=0; x < (ssize_t) image->columns; x++)\n {\n SetPixelRed(q,ScaleCharToQuantum(*p));\n SetPixelGreen(q,ScaleCharToQuantum(*(p+number_pixels)));\n SetPixelBlue(q,ScaleCharToQuantum(*(p+2*number_pixels)));\n if (image->colors != 0)\n {\n ssize_t\n index;", " index=(ssize_t) GetPixelRed(q);\n SetPixelRed(q,image->colormap[(ssize_t)\n ConstrainColormapIndex(image,index)].red);\n index=(ssize_t) GetPixelGreen(q);\n SetPixelGreen(q,image->colormap[(ssize_t)\n ConstrainColormapIndex(image,index)].green);\n index=(ssize_t) GetPixelRed(q);\n SetPixelBlue(q,image->colormap[(ssize_t)\n ConstrainColormapIndex(image,index)].blue);\n }\n SetPixelOpacity(q,image->matte != MagickFalse ? QuantumRange-\n ScaleCharToQuantum(*(p+number_pixels*3)) : OpaqueOpacity);\n p++;\n q++;\n }\n if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n }\n pixels=(unsigned char *) RelinquishMagickMemory(pixels);\n if (image->storage_class == PseudoClass)\n (void) SyncImage(image);\n if (EOFBlob(image) != MagickFalse)\n {\n ThrowFileException(exception,CorruptImageError,\"UnexpectedEndOfFile\",\n image->filename);\n break;\n }\n /*\n Proceed to next image.\n */\n if (image_info->number_scenes != 0)\n if (image->scene >= (image_info->scene+image_info->number_scenes-1))\n break;\n count=ReadBlob(image,1,&viff_info.identifier);\n if ((count != 0) && (viff_info.identifier == 0xab))\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);\n if (GetNextImageInList(image) == (Image *) NULL)\n {\n image=DestroyImageList(image);\n return((Image *) NULL);\n }\n image=SyncNextImageInList(image);\n status=SetImageProgress(image,LoadImagesTag,TellBlob(image),\n GetBlobSize(image));\n if (status == MagickFalse)\n break;\n }\n } while ((count != 0) && (viff_info.identifier == 0xab));\n (void) CloseBlob(image);\n return(GetFirstImageInList(image));\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 12480, "char_start": 12473, "chars": "MagickM" }, { "char_end": 12489, "char_start": 12482, "chars": "(number" }, { "char_end": 12493, "char_start": 12491, "chars": "ix" }, { "char_end": 12495, "char_start": 12494, "chars": "l" }, { "char_end": 12517, "char_start": 12504, "chars": "max_packets)," } ], "deleted": [ { "char_end": 12474, "char_start": 12473, "chars": "m" }, { "char_end": 12481, "char_start": 12478, "chars": "ack" }, { "char_end": 12483, "char_start": 12482, "chars": "t" } ] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/ca0c886abd6d3ef335eb74150cd23b89ebd17135", "file_name": "coders/viff.c", "func_name": "ReadVIFFImage", "line_changes": { "added": [ { "char_end": 12498, "char_start": 12423, "line": " pixels=(unsigned char *) AcquireQuantumMemory(MagickMax(number_pixels,\n", "line_no": 370 }, { "char_end": 12551, "char_start": 12498, "line": " max_packets),bytes_per_pixel*sizeof(*pixels));\n", "line_no": 371 } ], "deleted": [ { "char_end": 12486, "char_start": 12423, "line": " pixels=(unsigned char *) AcquireQuantumMemory(max_packets,\n", "line_no": 370 }, { "char_end": 12526, "char_start": 12486, "line": " bytes_per_pixel*sizeof(*pixels));\n", "line_no": 371 } ] }, "vul_type": "cwe-125" }
453
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int fmt) {\n\tint stacksize = r_config_get_i (core->config, \"esil.stack.depth\");\n\tbool iotrap = r_config_get_i (core->config, \"esil.iotrap\");\n\tbool romem = r_config_get_i (core->config, \"esil.romem\");\n\tbool stats = r_config_get_i (core->config, \"esil.stats\");\n\tbool be = core->print->big_endian;\n\tbool use_color = core->print->flags & R_PRINT_FLAGS_COLOR;\n\tcore->parser->relsub = r_config_get_i (core->config, \"asm.relsub\");\n\tint ret, i, j, idx, size;\n\tconst char *color = \"\";\n\tconst char *esilstr;\n\tconst char *opexstr;\n\tRAnalHint *hint;\n\tRAnalEsil *esil = NULL;\n\tRAsmOp asmop;\n\tRAnalOp op = {0};\n\tut64 addr;\n\tbool isFirst = true;\n\tunsigned int addrsize = r_config_get_i (core->config, \"esil.addr.size\");\n\tint totalsize = 0;", "\t// Variables required for setting up ESIL to REIL conversion\n\tif (use_color) {\n\t\tcolor = core->cons->pal.label;\n\t}\n\tswitch (fmt) {\n\tcase 'j':\n\t\tr_cons_printf (\"[\");\n\t\tbreak;\n\tcase 'r':\n\t\t// Setup for ESIL to REIL conversion\n\t\tesil = r_anal_esil_new (stacksize, iotrap, addrsize);\n\t\tif (!esil) {\n\t\t\treturn;\n\t\t}\n\t\tr_anal_esil_to_reil_setup (esil, core->anal, romem, stats);\n\t\tr_anal_esil_set_pc (esil, core->offset);\n\t\tbreak;\n\t}\n\tfor (i = idx = ret = 0; idx < len && (!nops || (nops && i < nops)); i++, idx += ret) {\n\t\taddr = core->offset + idx;\n\t\t// TODO: use more anal hints\n\t\thint = r_anal_hint_get (core->anal, addr);\n\t\tr_asm_set_pc (core->assembler, addr);\n\t\t(void)r_asm_disassemble (core->assembler, &asmop, buf + idx, len - idx);\n\t\tret = r_anal_op (core->anal, &op, core->offset + idx, buf + idx, len - idx, R_ANAL_OP_MASK_ESIL);\n\t\tesilstr = R_STRBUF_SAFEGET (&op.esil);\n\t\topexstr = R_STRBUF_SAFEGET (&op.opex);\n\t\tchar *mnem = strdup (r_asm_op_get_asm (&asmop));\n\t\tchar *sp = strchr (mnem, ' ');\n\t\tif (sp) {\n\t\t\t*sp = 0;\n\t\t\tif (op.prefix) {\n\t\t\t\tchar *arg = strdup (sp + 1);\n\t\t\t\tchar *sp = strchr (arg, ' ');\n\t\t\t\tif (sp) {\n\t\t\t\t\t*sp = 0;\n\t\t\t\t}\n\t\t\t\tfree (mnem);\n\t\t\t\tmnem = arg;\n\t\t\t}\n\t\t}\n\t\tif (ret < 1 && fmt != 'd') {\n\t\t\teprintf (\"Oops at 0x%08\" PFMT64x \" (\", core->offset + idx);\n\t\t\tfor (i = idx, j = 0; i < core->blocksize && j < 3; ++i, ++j) {\n\t\t\t\teprintf (\"%02x \", buf[i]);\n\t\t\t}\n\t\t\teprintf (\"...)\\n\");\n\t\t\tfree (mnem);\n\t\t\tbreak;\n\t\t}\n\t\tsize = (hint && hint->size)? hint->size: op.size;\n\t\tif (fmt == 'd') {\n\t\t\tchar *opname = strdup (r_asm_op_get_asm (&asmop));\n\t\t\tif (opname) {\n\t\t\t\tr_str_split (opname, ' ');\n\t\t\t\tchar *d = r_asm_describe (core->assembler, opname);\n\t\t\t\tif (d && *d) {\n\t\t\t\t\tr_cons_printf (\"%s: %s\\n\", opname, d);\n\t\t\t\t\tfree (d);\n\t\t\t\t} else {\n\t\t\t\t\teprintf (\"Unknown opcode\\n\");\n\t\t\t\t}\n\t\t\t\tfree (opname);\n\t\t\t}\n\t\t} else if (fmt == 'e') {\n\t\t\tif (*esilstr) {\n\t\t\t\tif (use_color) {\n\t\t\t\t\tr_cons_printf (\"%s0x%\" PFMT64x Color_RESET \" %s\\n\", color, core->offset + idx, esilstr);\n\t\t\t\t} else {\n\t\t\t\t\tr_cons_printf (\"0x%\" PFMT64x \" %s\\n\", core->offset + idx, esilstr);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (fmt == 's') {\n\t\t\ttotalsize += op.size;\n\t\t} else if (fmt == 'r') {\n\t\t\tif (*esilstr) {\n\t\t\t\tif (use_color) {\n\t\t\t\t\tr_cons_printf (\"%s0x%\" PFMT64x Color_RESET \"\\n\", color, core->offset + idx);\n\t\t\t\t} else {\n\t\t\t\t\tr_cons_printf (\"0x%\" PFMT64x \"\\n\", core->offset + idx);\n\t\t\t\t}\n\t\t\t\tr_anal_esil_parse (esil, esilstr);\n\t\t\t\tr_anal_esil_dumpstack (esil);\n\t\t\t\tr_anal_esil_stack_free (esil);\n\t\t\t}\n\t\t} else if (fmt == 'j') {\n\t\t\tif (isFirst) {\n\t\t\t\tisFirst = false;\n\t\t\t} else {\n\t\t\t\tr_cons_print (\",\");\n\t\t\t}\n\t\t\tr_cons_printf (\"{\\\"opcode\\\":\\\"%s\\\",\", r_asm_op_get_asm (&asmop));\n\t\t\t{\n\t\t\t\tchar strsub[128] = { 0 };\n\t\t\t\t// pc+33\n\t\t\t\tr_parse_varsub (core->parser, NULL,\n\t\t\t\t\tcore->offset + idx,\n\t\t\t\t\tasmop.size, r_asm_op_get_asm (&asmop),\n\t\t\t\t\tstrsub, sizeof (strsub));\n\t\t\t\t{\n\t\t\t\t\tut64 killme = UT64_MAX;\n\t\t\t\t\tif (r_io_read_i (core->io, op.ptr, &killme, op.refptr, be)) {\n\t\t\t\t\t\tcore->parser->relsub_addr = killme;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// 0x33->sym.xx\n\t\t\t\tchar *p = strdup (strsub);\n\t\t\t\tif (p) {\n\t\t\t\t\tr_parse_filter (core->parser, addr, core->flags, p,\n\t\t\t\t\t\t\tstrsub, sizeof (strsub), be);\n\t\t\t\t\tfree (p);\n\t\t\t\t}\n\t\t\t\tr_cons_printf (\"\\\"disasm\\\":\\\"%s\\\",\", strsub);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"mnemonic\\\":\\\"%s\\\",\", mnem);\n\t\t\tif (hint && hint->opcode) {\n\t\t\t\tr_cons_printf (\"\\\"ophint\\\":\\\"%s\\\",\", hint->opcode);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"sign\\\":%s,\", r_str_bool (op.sign));\n\t\t\tr_cons_printf (\"\\\"prefix\\\":%\" PFMT64u \",\", op.prefix);\n\t\t\tr_cons_printf (\"\\\"id\\\":%d,\", op.id);\n\t\t\tif (opexstr && *opexstr) {\n\t\t\t\tr_cons_printf (\"\\\"opex\\\":%s,\", opexstr);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"addr\\\":%\" PFMT64u \",\", core->offset + idx);\n\t\t\tr_cons_printf (\"\\\"bytes\\\":\\\"\");\n\t\t\tfor (j = 0; j < size; j++) {\n\t\t\t\tr_cons_printf (\"%02x\", buf[j + idx]);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\",\");\n\t\t\tif (op.val != UT64_MAX) {\n\t\t\t\tr_cons_printf (\"\\\"val\\\": %\" PFMT64u \",\", op.val);\n\t\t\t}\n\t\t\tif (op.ptr != UT64_MAX) {\n\t\t\t\tr_cons_printf (\"\\\"ptr\\\": %\" PFMT64u \",\", op.ptr);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"size\\\": %d,\", size);\n\t\t\tr_cons_printf (\"\\\"type\\\": \\\"%s\\\",\",\n\t\t\t\tr_anal_optype_to_string (op.type));\n\t\t\tif (op.reg) {\n\t\t\t\tr_cons_printf (\"\\\"reg\\\": \\\"%s\\\",\", op.reg);\n\t\t\t}\n\t\t\tif (op.ireg) {\n\t\t\t\tr_cons_printf (\"\\\"ireg\\\": \\\"%s\\\",\", op.ireg);\n\t\t\t}\n\t\t\tif (op.scale) {\n\t\t\t\tr_cons_printf (\"\\\"scale\\\":%d,\", op.scale);\n\t\t\t}\n\t\t\tif (hint && hint->esil) {\n\t\t\t\tr_cons_printf (\"\\\"esil\\\": \\\"%s\\\",\", hint->esil);\n\t\t\t} else if (*esilstr) {\n\t\t\t\tr_cons_printf (\"\\\"esil\\\": \\\"%s\\\",\", esilstr);\n\t\t\t}\n\t\t\tif (hint && hint->jump != UT64_MAX) {\n\t\t\t\top.jump = hint->jump;\n\t\t\t}\n\t\t\tif (op.jump != UT64_MAX) {\n\t\t\t\tr_cons_printf (\"\\\"jump\\\":%\" PFMT64u \",\", op.jump);\n\t\t\t}\n\t\t\tif (hint && hint->fail != UT64_MAX) {\n\t\t\t\top.fail = hint->fail;\n\t\t\t}\n\t\t\tif (op.refptr != -1) {\n\t\t\t\tr_cons_printf (\"\\\"refptr\\\":%d,\", op.refptr);\n\t\t\t}\n\t\t\tif (op.fail != UT64_MAX) {\n\t\t\t\tr_cons_printf (\"\\\"fail\\\":%\" PFMT64u \",\", op.fail);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"cycles\\\":%d,\", op.cycles);\n\t\t\tif (op.failcycles) {\n\t\t\t\tr_cons_printf (\"\\\"failcycles\\\":%d,\", op.failcycles);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"delay\\\":%d,\", op.delay);\n\t\t\t{\n\t\t\t\tconst char *p = r_anal_stackop_tostring (op.stackop);\n\t\t\t\tif (p && *p && strcmp (p, \"null\"))\n\t\t\t\t\tr_cons_printf (\"\\\"stack\\\":\\\"%s\\\",\", p);\n\t\t\t}\n\t\t\tif (op.stackptr) {\n\t\t\t\tr_cons_printf (\"\\\"stackptr\\\":%d,\", op.stackptr);\n\t\t\t}\n\t\t\t{\n\t\t\t\tconst char *arg = (op.type & R_ANAL_OP_TYPE_COND)\n\t\t\t\t\t? r_anal_cond_tostring (op.cond): NULL;\n\t\t\t\tif (arg) {\n\t\t\t\t\tr_cons_printf (\"\\\"cond\\\":\\\"%s\\\",\", arg);\n\t\t\t\t}\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"family\\\":\\\"%s\\\"}\", r_anal_op_family_to_string (op.family));\n\t\t} else {\n#define printline(k, fmt, arg)\\\n\t{ \\\n\t\tif (use_color)\\\n\t\t\tr_cons_printf (\"%s%s: \" Color_RESET, color, k);\\\n\t\telse\\\n\t\t\tr_cons_printf (\"%s: \", k);\\\n\t\tif (fmt) r_cons_printf (fmt, arg);\\\n\t}\n\t\t\tprintline (\"address\", \"0x%\" PFMT64x \"\\n\", core->offset + idx);\n\t\t\tprintline (\"opcode\", \"%s\\n\", r_asm_op_get_asm (&asmop));\n\t\t\tprintline (\"mnemonic\", \"%s\\n\", mnem);\n\t\t\tif (hint) {\n\t\t\t\tif (hint->opcode) {\n\t\t\t\t\tprintline (\"ophint\", \"%s\\n\", hint->opcode);\n\t\t\t\t}\n#if 0\n\t\t\t\t// addr should not override core->offset + idx.. its silly\n\t\t\t\tif (hint->addr != UT64_MAX) {\n\t\t\t\t\tprintline (\"addr\", \"0x%08\" PFMT64x \"\\n\", (hint->addr + idx));\n\t\t\t\t}\n#endif\n\t\t\t}\n\t\t\tprintline (\"prefix\", \"%\" PFMT64u \"\\n\", op.prefix);\n\t\t\tprintline (\"id\", \"%d\\n\", op.id);\n#if 0\n// no opex here to avoid lot of tests broken..and having json in here is not much useful imho\n\t\t\tif (opexstr && *opexstr) {\n\t\t\t\tprintline (\"opex\", \"%s\\n\", opexstr);\n\t\t\t}\n#endif\n\t\t\tprintline (\"bytes\", NULL, 0);", "\t\t\tfor (j = 0; j < size; j++) {\n\t\t\t\tr_cons_printf (\"%02x\", buf[j + idx]);", "\t\t\t}\n\t\t\tr_cons_newline ();", "\t\t\tif (op.val != UT64_MAX)", "\t\t\t\tprintline (\"val\", \"0x%08\" PFMT64x \"\\n\", op.val);", "\t\t\tif (op.ptr != UT64_MAX)", "\t\t\t\tprintline (\"ptr\", \"0x%08\" PFMT64x \"\\n\", op.ptr);", "\t\t\tif (op.refptr != -1)", "\t\t\t\tprintline (\"refptr\", \"%d\\n\", op.refptr);", "", "\t\t\tprintline (\"size\", \"%d\\n\", size);\n\t\t\tprintline (\"sign\", \"%s\\n\", r_str_bool (op.sign));\n\t\t\tprintline (\"type\", \"%s\\n\", r_anal_optype_to_string (op.type));\n\t\t\tprintline (\"cycles\", \"%d\\n\", op.cycles);\n\t\t\tif (op.failcycles) {\n\t\t\t\tprintline (\"failcycles\", \"%d\\n\", op.failcycles);\n\t\t\t}\n\t\t\t{\n\t\t\t\tconst char *t2 = r_anal_optype_to_string (op.type2);\n\t\t\t\tif (t2 && strcmp (t2, \"null\")) {\n\t\t\t\t\tprintline (\"type2\", \"%s\\n\", t2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (op.reg) {\n\t\t\t\tprintline (\"reg\", \"%s\\n\", op.reg);\n\t\t\t}\n\t\t\tif (op.ireg) {\n\t\t\t\tprintline (\"ireg\", \"%s\\n\", op.ireg);\n\t\t\t}\n\t\t\tif (op.scale) {\n\t\t\t\tprintline (\"scale\", \"%d\\n\", op.scale);\n\t\t\t}\n\t\t\tif (hint && hint->esil) {\n\t\t\t\tprintline (\"esil\", \"%s\\n\", hint->esil);\n\t\t\t} else if (*esilstr) {\n\t\t\t\tprintline (\"esil\", \"%s\\n\", esilstr);\n\t\t\t}\n\t\t\tif (hint && hint->jump != UT64_MAX) {\n\t\t\t\top.jump = hint->jump;\n\t\t\t}\n\t\t\tif (op.jump != UT64_MAX) {\n\t\t\t\tprintline (\"jump\", \"0x%08\" PFMT64x \"\\n\", op.jump);\n\t\t\t}\n\t\t\tif (op.direction != 0) {\n\t\t\t\tconst char * dir = op.direction == 1 ? \"read\"\n\t\t\t\t\t: op.direction == 2 ? \"write\"\n\t\t\t\t\t: op.direction == 4 ? \"exec\"\n\t\t\t\t\t: op.direction == 8 ? \"ref\": \"none\";\n\t\t\t\tprintline (\"direction\", \"%s\\n\", dir);\n\t\t\t}\n\t\t\tif (hint && hint->fail != UT64_MAX) {\n\t\t\t\top.fail = hint->fail;\n\t\t\t}\n\t\t\tif (op.fail != UT64_MAX) {\n\t\t\t\tprintline (\"fail\", \"0x%08\" PFMT64x \"\\n\", op.fail);\n\t\t\t}\n\t\t\tif (op.delay) {\n\t\t\t\tprintline (\"delay\", \"%d\\n\", op.delay);\n\t\t\t}\n\t\t\tprintline (\"stack\", \"%s\\n\", r_anal_stackop_tostring (op.stackop));\n\t\t\t{\n\t\t\t\tconst char *arg = (op.type & R_ANAL_OP_TYPE_COND)? r_anal_cond_tostring (op.cond): NULL;\n\t\t\t\tif (arg) {\n\t\t\t\t\tprintline (\"cond\", \"%s\\n\", arg);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprintline (\"family\", \"%s\\n\", r_anal_op_family_to_string (op.family));\n\t\t\tprintline (\"stackop\", \"%s\\n\", r_anal_stackop_tostring (op.stackop));\n\t\t\tif (op.stackptr) {\n\t\t\t\tprintline (\"stackptr\", \"%\"PFMT64u\"\\n\", op.stackptr);\n\t\t\t}\n\t\t}\n\t\t//r_cons_printf (\"false: 0x%08\"PFMT64x\"\\n\", core->offset+idx);\n\t\t//free (hint);\n\t\tfree (mnem);\n\t\tr_anal_hint_free (hint);\n\t\tr_anal_op_fini (&op);\n\t}\n\tr_anal_op_fini (&op);\n\tif (fmt == 'j') {\n\t\tr_cons_printf (\"]\");\n\t\tr_cons_newline ();\n\t} else if (fmt == 's') {\n\t\tr_cons_printf (\"%d\\n\", totalsize);\n\t}\n\tr_anal_esil_free (esil);\n}" ]
[ 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 7379, "char_start": 7316, "chars": "int minsz = R_MIN (len, size);\n\t\t\tminsz = R_MAX (minsz, 0);\n\t\t\t" }, { "char_end": 7396, "char_start": 7395, "chars": "m" }, { "char_end": 7399, "char_start": 7397, "chars": "ns" }, { "char_end": 7471, "char_start": 7413, "chars": "ut8 ch = ((j + idx - 1) > minsz)? 0xff: buf[j + idx];\n\t\t\t\t" }, { "char_end": 7496, "char_start": 7494, "chars": "ch" }, { "char_end": 7554, "char_start": 7552, "chars": " {" }, { "char_end": 7616, "char_start": 7611, "chars": "}\n\t\t\t" }, { "char_end": 7641, "char_start": 7639, "chars": " {" }, { "char_end": 7703, "char_start": 7698, "chars": "}\n\t\t\t" }, { "char_end": 7725, "char_start": 7723, "chars": " {" }, { "char_end": 7775, "char_start": 7770, "chars": "\n\t\t\t}" } ], "deleted": [ { "char_end": 7334, "char_start": 7333, "chars": "i" }, { "char_end": 7336, "char_start": 7335, "chars": "e" }, { "char_end": 7384, "char_start": 7372, "chars": "buf[j + idx]" } ] }, "commit_link": "github.com/radare/radare2/commit/a1bc65c3db593530775823d6d7506a457ed95267", "file_name": "libr/core/cmd_anal.c", "func_name": "core_anal_bytes", "line_changes": { "added": [ { "char_end": 7347, "char_start": 7313, "line": "\t\t\tint minsz = R_MIN (len, size);\n", "line_no": 243 }, { "char_end": 7376, "char_start": 7347, "line": "\t\t\tminsz = R_MAX (minsz, 0);\n", "line_no": 244 }, { "char_end": 7409, "char_start": 7376, "line": "\t\t\tfor (j = 0; j < minsz; j++) {\n", "line_no": 245 }, { "char_end": 7467, "char_start": 7409, "line": "\t\t\t\tut8 ch = ((j + idx - 1) > minsz)? 0xff: buf[j + idx];\n", "line_no": 246 }, { "char_end": 7499, "char_start": 7467, "line": "\t\t\t\tr_cons_printf (\"%02x\", ch);\n", "line_no": 247 }, { "char_end": 7555, "char_start": 7526, "line": "\t\t\tif (op.val != UT64_MAX) {\n", "line_no": 250 }, { "char_end": 7613, "char_start": 7608, "line": "\t\t\t}\n", "line_no": 252 }, { "char_end": 7642, "char_start": 7613, "line": "\t\t\tif (op.ptr != UT64_MAX) {\n", "line_no": 253 }, { "char_end": 7700, "char_start": 7695, "line": "\t\t\t}\n", "line_no": 255 }, { "char_end": 7726, "char_start": 7700, "line": "\t\t\tif (op.refptr != -1) {\n", "line_no": 256 }, { "char_end": 7776, "char_start": 7771, "line": "\t\t\t}\n", "line_no": 258 } ], "deleted": [ { "char_end": 7345, "char_start": 7313, "line": "\t\t\tfor (j = 0; j < size; j++) {\n", "line_no": 243 }, { "char_end": 7387, "char_start": 7345, "line": "\t\t\t\tr_cons_printf (\"%02x\", buf[j + idx]);\n", "line_no": 244 }, { "char_end": 7441, "char_start": 7414, "line": "\t\t\tif (op.val != UT64_MAX)\n", "line_no": 247 }, { "char_end": 7521, "char_start": 7494, "line": "\t\t\tif (op.ptr != UT64_MAX)\n", "line_no": 249 }, { "char_end": 7598, "char_start": 7574, "line": "\t\t\tif (op.refptr != -1)\n", "line_no": 251 } ] }, "vul_type": "cwe-125" }
454
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int fmt) {\n\tint stacksize = r_config_get_i (core->config, \"esil.stack.depth\");\n\tbool iotrap = r_config_get_i (core->config, \"esil.iotrap\");\n\tbool romem = r_config_get_i (core->config, \"esil.romem\");\n\tbool stats = r_config_get_i (core->config, \"esil.stats\");\n\tbool be = core->print->big_endian;\n\tbool use_color = core->print->flags & R_PRINT_FLAGS_COLOR;\n\tcore->parser->relsub = r_config_get_i (core->config, \"asm.relsub\");\n\tint ret, i, j, idx, size;\n\tconst char *color = \"\";\n\tconst char *esilstr;\n\tconst char *opexstr;\n\tRAnalHint *hint;\n\tRAnalEsil *esil = NULL;\n\tRAsmOp asmop;\n\tRAnalOp op = {0};\n\tut64 addr;\n\tbool isFirst = true;\n\tunsigned int addrsize = r_config_get_i (core->config, \"esil.addr.size\");\n\tint totalsize = 0;", "\t// Variables required for setting up ESIL to REIL conversion\n\tif (use_color) {\n\t\tcolor = core->cons->pal.label;\n\t}\n\tswitch (fmt) {\n\tcase 'j':\n\t\tr_cons_printf (\"[\");\n\t\tbreak;\n\tcase 'r':\n\t\t// Setup for ESIL to REIL conversion\n\t\tesil = r_anal_esil_new (stacksize, iotrap, addrsize);\n\t\tif (!esil) {\n\t\t\treturn;\n\t\t}\n\t\tr_anal_esil_to_reil_setup (esil, core->anal, romem, stats);\n\t\tr_anal_esil_set_pc (esil, core->offset);\n\t\tbreak;\n\t}\n\tfor (i = idx = ret = 0; idx < len && (!nops || (nops && i < nops)); i++, idx += ret) {\n\t\taddr = core->offset + idx;\n\t\t// TODO: use more anal hints\n\t\thint = r_anal_hint_get (core->anal, addr);\n\t\tr_asm_set_pc (core->assembler, addr);\n\t\t(void)r_asm_disassemble (core->assembler, &asmop, buf + idx, len - idx);\n\t\tret = r_anal_op (core->anal, &op, core->offset + idx, buf + idx, len - idx, R_ANAL_OP_MASK_ESIL);\n\t\tesilstr = R_STRBUF_SAFEGET (&op.esil);\n\t\topexstr = R_STRBUF_SAFEGET (&op.opex);\n\t\tchar *mnem = strdup (r_asm_op_get_asm (&asmop));\n\t\tchar *sp = strchr (mnem, ' ');\n\t\tif (sp) {\n\t\t\t*sp = 0;\n\t\t\tif (op.prefix) {\n\t\t\t\tchar *arg = strdup (sp + 1);\n\t\t\t\tchar *sp = strchr (arg, ' ');\n\t\t\t\tif (sp) {\n\t\t\t\t\t*sp = 0;\n\t\t\t\t}\n\t\t\t\tfree (mnem);\n\t\t\t\tmnem = arg;\n\t\t\t}\n\t\t}\n\t\tif (ret < 1 && fmt != 'd') {\n\t\t\teprintf (\"Oops at 0x%08\" PFMT64x \" (\", core->offset + idx);\n\t\t\tfor (i = idx, j = 0; i < core->blocksize && j < 3; ++i, ++j) {\n\t\t\t\teprintf (\"%02x \", buf[i]);\n\t\t\t}\n\t\t\teprintf (\"...)\\n\");\n\t\t\tfree (mnem);\n\t\t\tbreak;\n\t\t}\n\t\tsize = (hint && hint->size)? hint->size: op.size;\n\t\tif (fmt == 'd') {\n\t\t\tchar *opname = strdup (r_asm_op_get_asm (&asmop));\n\t\t\tif (opname) {\n\t\t\t\tr_str_split (opname, ' ');\n\t\t\t\tchar *d = r_asm_describe (core->assembler, opname);\n\t\t\t\tif (d && *d) {\n\t\t\t\t\tr_cons_printf (\"%s: %s\\n\", opname, d);\n\t\t\t\t\tfree (d);\n\t\t\t\t} else {\n\t\t\t\t\teprintf (\"Unknown opcode\\n\");\n\t\t\t\t}\n\t\t\t\tfree (opname);\n\t\t\t}\n\t\t} else if (fmt == 'e') {\n\t\t\tif (*esilstr) {\n\t\t\t\tif (use_color) {\n\t\t\t\t\tr_cons_printf (\"%s0x%\" PFMT64x Color_RESET \" %s\\n\", color, core->offset + idx, esilstr);\n\t\t\t\t} else {\n\t\t\t\t\tr_cons_printf (\"0x%\" PFMT64x \" %s\\n\", core->offset + idx, esilstr);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (fmt == 's') {\n\t\t\ttotalsize += op.size;\n\t\t} else if (fmt == 'r') {\n\t\t\tif (*esilstr) {\n\t\t\t\tif (use_color) {\n\t\t\t\t\tr_cons_printf (\"%s0x%\" PFMT64x Color_RESET \"\\n\", color, core->offset + idx);\n\t\t\t\t} else {\n\t\t\t\t\tr_cons_printf (\"0x%\" PFMT64x \"\\n\", core->offset + idx);\n\t\t\t\t}\n\t\t\t\tr_anal_esil_parse (esil, esilstr);\n\t\t\t\tr_anal_esil_dumpstack (esil);\n\t\t\t\tr_anal_esil_stack_free (esil);\n\t\t\t}\n\t\t} else if (fmt == 'j') {\n\t\t\tif (isFirst) {\n\t\t\t\tisFirst = false;\n\t\t\t} else {\n\t\t\t\tr_cons_print (\",\");\n\t\t\t}\n\t\t\tr_cons_printf (\"{\\\"opcode\\\":\\\"%s\\\",\", r_asm_op_get_asm (&asmop));\n\t\t\t{\n\t\t\t\tchar strsub[128] = { 0 };\n\t\t\t\t// pc+33\n\t\t\t\tr_parse_varsub (core->parser, NULL,\n\t\t\t\t\tcore->offset + idx,\n\t\t\t\t\tasmop.size, r_asm_op_get_asm (&asmop),\n\t\t\t\t\tstrsub, sizeof (strsub));\n\t\t\t\t{\n\t\t\t\t\tut64 killme = UT64_MAX;\n\t\t\t\t\tif (r_io_read_i (core->io, op.ptr, &killme, op.refptr, be)) {\n\t\t\t\t\t\tcore->parser->relsub_addr = killme;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// 0x33->sym.xx\n\t\t\t\tchar *p = strdup (strsub);\n\t\t\t\tif (p) {\n\t\t\t\t\tr_parse_filter (core->parser, addr, core->flags, p,\n\t\t\t\t\t\t\tstrsub, sizeof (strsub), be);\n\t\t\t\t\tfree (p);\n\t\t\t\t}\n\t\t\t\tr_cons_printf (\"\\\"disasm\\\":\\\"%s\\\",\", strsub);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"mnemonic\\\":\\\"%s\\\",\", mnem);\n\t\t\tif (hint && hint->opcode) {\n\t\t\t\tr_cons_printf (\"\\\"ophint\\\":\\\"%s\\\",\", hint->opcode);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"sign\\\":%s,\", r_str_bool (op.sign));\n\t\t\tr_cons_printf (\"\\\"prefix\\\":%\" PFMT64u \",\", op.prefix);\n\t\t\tr_cons_printf (\"\\\"id\\\":%d,\", op.id);\n\t\t\tif (opexstr && *opexstr) {\n\t\t\t\tr_cons_printf (\"\\\"opex\\\":%s,\", opexstr);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"addr\\\":%\" PFMT64u \",\", core->offset + idx);\n\t\t\tr_cons_printf (\"\\\"bytes\\\":\\\"\");\n\t\t\tfor (j = 0; j < size; j++) {\n\t\t\t\tr_cons_printf (\"%02x\", buf[j + idx]);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\",\");\n\t\t\tif (op.val != UT64_MAX) {\n\t\t\t\tr_cons_printf (\"\\\"val\\\": %\" PFMT64u \",\", op.val);\n\t\t\t}\n\t\t\tif (op.ptr != UT64_MAX) {\n\t\t\t\tr_cons_printf (\"\\\"ptr\\\": %\" PFMT64u \",\", op.ptr);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"size\\\": %d,\", size);\n\t\t\tr_cons_printf (\"\\\"type\\\": \\\"%s\\\",\",\n\t\t\t\tr_anal_optype_to_string (op.type));\n\t\t\tif (op.reg) {\n\t\t\t\tr_cons_printf (\"\\\"reg\\\": \\\"%s\\\",\", op.reg);\n\t\t\t}\n\t\t\tif (op.ireg) {\n\t\t\t\tr_cons_printf (\"\\\"ireg\\\": \\\"%s\\\",\", op.ireg);\n\t\t\t}\n\t\t\tif (op.scale) {\n\t\t\t\tr_cons_printf (\"\\\"scale\\\":%d,\", op.scale);\n\t\t\t}\n\t\t\tif (hint && hint->esil) {\n\t\t\t\tr_cons_printf (\"\\\"esil\\\": \\\"%s\\\",\", hint->esil);\n\t\t\t} else if (*esilstr) {\n\t\t\t\tr_cons_printf (\"\\\"esil\\\": \\\"%s\\\",\", esilstr);\n\t\t\t}\n\t\t\tif (hint && hint->jump != UT64_MAX) {\n\t\t\t\top.jump = hint->jump;\n\t\t\t}\n\t\t\tif (op.jump != UT64_MAX) {\n\t\t\t\tr_cons_printf (\"\\\"jump\\\":%\" PFMT64u \",\", op.jump);\n\t\t\t}\n\t\t\tif (hint && hint->fail != UT64_MAX) {\n\t\t\t\top.fail = hint->fail;\n\t\t\t}\n\t\t\tif (op.refptr != -1) {\n\t\t\t\tr_cons_printf (\"\\\"refptr\\\":%d,\", op.refptr);\n\t\t\t}\n\t\t\tif (op.fail != UT64_MAX) {\n\t\t\t\tr_cons_printf (\"\\\"fail\\\":%\" PFMT64u \",\", op.fail);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"cycles\\\":%d,\", op.cycles);\n\t\t\tif (op.failcycles) {\n\t\t\t\tr_cons_printf (\"\\\"failcycles\\\":%d,\", op.failcycles);\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"delay\\\":%d,\", op.delay);\n\t\t\t{\n\t\t\t\tconst char *p = r_anal_stackop_tostring (op.stackop);\n\t\t\t\tif (p && *p && strcmp (p, \"null\"))\n\t\t\t\t\tr_cons_printf (\"\\\"stack\\\":\\\"%s\\\",\", p);\n\t\t\t}\n\t\t\tif (op.stackptr) {\n\t\t\t\tr_cons_printf (\"\\\"stackptr\\\":%d,\", op.stackptr);\n\t\t\t}\n\t\t\t{\n\t\t\t\tconst char *arg = (op.type & R_ANAL_OP_TYPE_COND)\n\t\t\t\t\t? r_anal_cond_tostring (op.cond): NULL;\n\t\t\t\tif (arg) {\n\t\t\t\t\tr_cons_printf (\"\\\"cond\\\":\\\"%s\\\",\", arg);\n\t\t\t\t}\n\t\t\t}\n\t\t\tr_cons_printf (\"\\\"family\\\":\\\"%s\\\"}\", r_anal_op_family_to_string (op.family));\n\t\t} else {\n#define printline(k, fmt, arg)\\\n\t{ \\\n\t\tif (use_color)\\\n\t\t\tr_cons_printf (\"%s%s: \" Color_RESET, color, k);\\\n\t\telse\\\n\t\t\tr_cons_printf (\"%s: \", k);\\\n\t\tif (fmt) r_cons_printf (fmt, arg);\\\n\t}\n\t\t\tprintline (\"address\", \"0x%\" PFMT64x \"\\n\", core->offset + idx);\n\t\t\tprintline (\"opcode\", \"%s\\n\", r_asm_op_get_asm (&asmop));\n\t\t\tprintline (\"mnemonic\", \"%s\\n\", mnem);\n\t\t\tif (hint) {\n\t\t\t\tif (hint->opcode) {\n\t\t\t\t\tprintline (\"ophint\", \"%s\\n\", hint->opcode);\n\t\t\t\t}\n#if 0\n\t\t\t\t// addr should not override core->offset + idx.. its silly\n\t\t\t\tif (hint->addr != UT64_MAX) {\n\t\t\t\t\tprintline (\"addr\", \"0x%08\" PFMT64x \"\\n\", (hint->addr + idx));\n\t\t\t\t}\n#endif\n\t\t\t}\n\t\t\tprintline (\"prefix\", \"%\" PFMT64u \"\\n\", op.prefix);\n\t\t\tprintline (\"id\", \"%d\\n\", op.id);\n#if 0\n// no opex here to avoid lot of tests broken..and having json in here is not much useful imho\n\t\t\tif (opexstr && *opexstr) {\n\t\t\t\tprintline (\"opex\", \"%s\\n\", opexstr);\n\t\t\t}\n#endif\n\t\t\tprintline (\"bytes\", NULL, 0);", "\t\t\tint minsz = R_MIN (len, size);\n\t\t\tminsz = R_MAX (minsz, 0);\n\t\t\tfor (j = 0; j < minsz; j++) {\n\t\t\t\tut8 ch = ((j + idx - 1) > minsz)? 0xff: buf[j + idx];\n\t\t\t\tr_cons_printf (\"%02x\", ch);", "\t\t\t}\n\t\t\tr_cons_newline ();", "\t\t\tif (op.val != UT64_MAX) {", "\t\t\t\tprintline (\"val\", \"0x%08\" PFMT64x \"\\n\", op.val);", "\t\t\t}\n\t\t\tif (op.ptr != UT64_MAX) {", "\t\t\t\tprintline (\"ptr\", \"0x%08\" PFMT64x \"\\n\", op.ptr);", "\t\t\t}\n\t\t\tif (op.refptr != -1) {", "\t\t\t\tprintline (\"refptr\", \"%d\\n\", op.refptr);", "\t\t\t}", "\t\t\tprintline (\"size\", \"%d\\n\", size);\n\t\t\tprintline (\"sign\", \"%s\\n\", r_str_bool (op.sign));\n\t\t\tprintline (\"type\", \"%s\\n\", r_anal_optype_to_string (op.type));\n\t\t\tprintline (\"cycles\", \"%d\\n\", op.cycles);\n\t\t\tif (op.failcycles) {\n\t\t\t\tprintline (\"failcycles\", \"%d\\n\", op.failcycles);\n\t\t\t}\n\t\t\t{\n\t\t\t\tconst char *t2 = r_anal_optype_to_string (op.type2);\n\t\t\t\tif (t2 && strcmp (t2, \"null\")) {\n\t\t\t\t\tprintline (\"type2\", \"%s\\n\", t2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (op.reg) {\n\t\t\t\tprintline (\"reg\", \"%s\\n\", op.reg);\n\t\t\t}\n\t\t\tif (op.ireg) {\n\t\t\t\tprintline (\"ireg\", \"%s\\n\", op.ireg);\n\t\t\t}\n\t\t\tif (op.scale) {\n\t\t\t\tprintline (\"scale\", \"%d\\n\", op.scale);\n\t\t\t}\n\t\t\tif (hint && hint->esil) {\n\t\t\t\tprintline (\"esil\", \"%s\\n\", hint->esil);\n\t\t\t} else if (*esilstr) {\n\t\t\t\tprintline (\"esil\", \"%s\\n\", esilstr);\n\t\t\t}\n\t\t\tif (hint && hint->jump != UT64_MAX) {\n\t\t\t\top.jump = hint->jump;\n\t\t\t}\n\t\t\tif (op.jump != UT64_MAX) {\n\t\t\t\tprintline (\"jump\", \"0x%08\" PFMT64x \"\\n\", op.jump);\n\t\t\t}\n\t\t\tif (op.direction != 0) {\n\t\t\t\tconst char * dir = op.direction == 1 ? \"read\"\n\t\t\t\t\t: op.direction == 2 ? \"write\"\n\t\t\t\t\t: op.direction == 4 ? \"exec\"\n\t\t\t\t\t: op.direction == 8 ? \"ref\": \"none\";\n\t\t\t\tprintline (\"direction\", \"%s\\n\", dir);\n\t\t\t}\n\t\t\tif (hint && hint->fail != UT64_MAX) {\n\t\t\t\top.fail = hint->fail;\n\t\t\t}\n\t\t\tif (op.fail != UT64_MAX) {\n\t\t\t\tprintline (\"fail\", \"0x%08\" PFMT64x \"\\n\", op.fail);\n\t\t\t}\n\t\t\tif (op.delay) {\n\t\t\t\tprintline (\"delay\", \"%d\\n\", op.delay);\n\t\t\t}\n\t\t\tprintline (\"stack\", \"%s\\n\", r_anal_stackop_tostring (op.stackop));\n\t\t\t{\n\t\t\t\tconst char *arg = (op.type & R_ANAL_OP_TYPE_COND)? r_anal_cond_tostring (op.cond): NULL;\n\t\t\t\tif (arg) {\n\t\t\t\t\tprintline (\"cond\", \"%s\\n\", arg);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprintline (\"family\", \"%s\\n\", r_anal_op_family_to_string (op.family));\n\t\t\tprintline (\"stackop\", \"%s\\n\", r_anal_stackop_tostring (op.stackop));\n\t\t\tif (op.stackptr) {\n\t\t\t\tprintline (\"stackptr\", \"%\"PFMT64u\"\\n\", op.stackptr);\n\t\t\t}\n\t\t}\n\t\t//r_cons_printf (\"false: 0x%08\"PFMT64x\"\\n\", core->offset+idx);\n\t\t//free (hint);\n\t\tfree (mnem);\n\t\tr_anal_hint_free (hint);\n\t\tr_anal_op_fini (&op);\n\t}\n\tr_anal_op_fini (&op);\n\tif (fmt == 'j') {\n\t\tr_cons_printf (\"]\");\n\t\tr_cons_newline ();\n\t} else if (fmt == 's') {\n\t\tr_cons_printf (\"%d\\n\", totalsize);\n\t}\n\tr_anal_esil_free (esil);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 7379, "char_start": 7316, "chars": "int minsz = R_MIN (len, size);\n\t\t\tminsz = R_MAX (minsz, 0);\n\t\t\t" }, { "char_end": 7396, "char_start": 7395, "chars": "m" }, { "char_end": 7399, "char_start": 7397, "chars": "ns" }, { "char_end": 7471, "char_start": 7413, "chars": "ut8 ch = ((j + idx - 1) > minsz)? 0xff: buf[j + idx];\n\t\t\t\t" }, { "char_end": 7496, "char_start": 7494, "chars": "ch" }, { "char_end": 7554, "char_start": 7552, "chars": " {" }, { "char_end": 7616, "char_start": 7611, "chars": "}\n\t\t\t" }, { "char_end": 7641, "char_start": 7639, "chars": " {" }, { "char_end": 7703, "char_start": 7698, "chars": "}\n\t\t\t" }, { "char_end": 7725, "char_start": 7723, "chars": " {" }, { "char_end": 7775, "char_start": 7770, "chars": "\n\t\t\t}" } ], "deleted": [ { "char_end": 7334, "char_start": 7333, "chars": "i" }, { "char_end": 7336, "char_start": 7335, "chars": "e" }, { "char_end": 7384, "char_start": 7372, "chars": "buf[j + idx]" } ] }, "commit_link": "github.com/radare/radare2/commit/a1bc65c3db593530775823d6d7506a457ed95267", "file_name": "libr/core/cmd_anal.c", "func_name": "core_anal_bytes", "line_changes": { "added": [ { "char_end": 7347, "char_start": 7313, "line": "\t\t\tint minsz = R_MIN (len, size);\n", "line_no": 243 }, { "char_end": 7376, "char_start": 7347, "line": "\t\t\tminsz = R_MAX (minsz, 0);\n", "line_no": 244 }, { "char_end": 7409, "char_start": 7376, "line": "\t\t\tfor (j = 0; j < minsz; j++) {\n", "line_no": 245 }, { "char_end": 7467, "char_start": 7409, "line": "\t\t\t\tut8 ch = ((j + idx - 1) > minsz)? 0xff: buf[j + idx];\n", "line_no": 246 }, { "char_end": 7499, "char_start": 7467, "line": "\t\t\t\tr_cons_printf (\"%02x\", ch);\n", "line_no": 247 }, { "char_end": 7555, "char_start": 7526, "line": "\t\t\tif (op.val != UT64_MAX) {\n", "line_no": 250 }, { "char_end": 7613, "char_start": 7608, "line": "\t\t\t}\n", "line_no": 252 }, { "char_end": 7642, "char_start": 7613, "line": "\t\t\tif (op.ptr != UT64_MAX) {\n", "line_no": 253 }, { "char_end": 7700, "char_start": 7695, "line": "\t\t\t}\n", "line_no": 255 }, { "char_end": 7726, "char_start": 7700, "line": "\t\t\tif (op.refptr != -1) {\n", "line_no": 256 }, { "char_end": 7776, "char_start": 7771, "line": "\t\t\t}\n", "line_no": 258 } ], "deleted": [ { "char_end": 7345, "char_start": 7313, "line": "\t\t\tfor (j = 0; j < size; j++) {\n", "line_no": 243 }, { "char_end": 7387, "char_start": 7345, "line": "\t\t\t\tr_cons_printf (\"%02x\", buf[j + idx]);\n", "line_no": 244 }, { "char_end": 7441, "char_start": 7414, "line": "\t\t\tif (op.val != UT64_MAX)\n", "line_no": 247 }, { "char_end": 7521, "char_start": 7494, "line": "\t\t\tif (op.ptr != UT64_MAX)\n", "line_no": 249 }, { "char_end": 7598, "char_start": 7574, "line": "\t\t\tif (op.refptr != -1)\n", "line_no": 251 } ] }, "vul_type": "cwe-125" }
454
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static BOOL update_read_bitmap_data(rdpUpdate* update, wStream* s, BITMAP_DATA* bitmapData)\n{\n\tWINPR_UNUSED(update);\n\tif (Stream_GetRemainingLength(s) < 18)\n\t\treturn FALSE;", "\tStream_Read_UINT16(s, bitmapData->destLeft);\n\tStream_Read_UINT16(s, bitmapData->destTop);\n\tStream_Read_UINT16(s, bitmapData->destRight);\n\tStream_Read_UINT16(s, bitmapData->destBottom);\n\tStream_Read_UINT16(s, bitmapData->width);\n\tStream_Read_UINT16(s, bitmapData->height);\n\tStream_Read_UINT16(s, bitmapData->bitsPerPixel);\n\tStream_Read_UINT16(s, bitmapData->flags);\n\tStream_Read_UINT16(s, bitmapData->bitmapLength);", "\tif (bitmapData->flags & BITMAP_COMPRESSION)\n\t{\n\t\tif (!(bitmapData->flags & NO_BITMAP_COMPRESSION_HDR))\n\t\t{", "", "\t\t\tStream_Read_UINT16(s,\n\t\t\t bitmapData->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */\n\t\t\tStream_Read_UINT16(s,\n\t\t\t bitmapData->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */\n\t\t\tStream_Read_UINT16(s, bitmapData->cbScanWidth); /* cbScanWidth (2 bytes) */\n\t\t\tStream_Read_UINT16(s,\n\t\t\t bitmapData->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */\n\t\t\tbitmapData->bitmapLength = bitmapData->cbCompMainBodySize;\n\t\t}", "\t\tbitmapData->compressed = TRUE;\n\t}\n\telse\n\t\tbitmapData->compressed = FALSE;", "\tif (Stream_GetRemainingLength(s) < bitmapData->bitmapLength)\n\t\treturn FALSE;", "\tif (bitmapData->bitmapLength > 0)\n\t{\n\t\tbitmapData->bitmapDataStream = malloc(bitmapData->bitmapLength);", "\t\tif (!bitmapData->bitmapDataStream)\n\t\t\treturn FALSE;", "\t\tmemcpy(bitmapData->bitmapDataStream, Stream_Pointer(s), bitmapData->bitmapLength);\n\t\tStream_Seek(s, bitmapData->bitmapLength);\n\t}", "\treturn TRUE;\n}" ]
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 762, "char_start": 702, "chars": "if (Stream_GetRemainingLength(s) < 8)\n\t\t\t\treturn FALSE;\n\n\t\t\t" } ], "deleted": [] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/f8890a645c221823ac133dbf991f8a65ae50d637", "file_name": "libfreerdp/core/update.c", "func_name": "update_read_bitmap_data", "line_changes": { "added": [ { "char_end": 740, "char_start": 699, "line": "\t\t\tif (Stream_GetRemainingLength(s) < 8)\n", "line_no": 21 }, { "char_end": 758, "char_start": 740, "line": "\t\t\t\treturn FALSE;\n", "line_no": 22 }, { "char_end": 759, "char_start": 758, "line": "\n", "line_no": 23 } ], "deleted": [] }, "vul_type": "cwe-125" }
455
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static BOOL update_read_bitmap_data(rdpUpdate* update, wStream* s, BITMAP_DATA* bitmapData)\n{\n\tWINPR_UNUSED(update);\n\tif (Stream_GetRemainingLength(s) < 18)\n\t\treturn FALSE;", "\tStream_Read_UINT16(s, bitmapData->destLeft);\n\tStream_Read_UINT16(s, bitmapData->destTop);\n\tStream_Read_UINT16(s, bitmapData->destRight);\n\tStream_Read_UINT16(s, bitmapData->destBottom);\n\tStream_Read_UINT16(s, bitmapData->width);\n\tStream_Read_UINT16(s, bitmapData->height);\n\tStream_Read_UINT16(s, bitmapData->bitsPerPixel);\n\tStream_Read_UINT16(s, bitmapData->flags);\n\tStream_Read_UINT16(s, bitmapData->bitmapLength);", "\tif (bitmapData->flags & BITMAP_COMPRESSION)\n\t{\n\t\tif (!(bitmapData->flags & NO_BITMAP_COMPRESSION_HDR))\n\t\t{", "\t\t\tif (Stream_GetRemainingLength(s) < 8)\n\t\t\t\treturn FALSE;\n", "\t\t\tStream_Read_UINT16(s,\n\t\t\t bitmapData->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */\n\t\t\tStream_Read_UINT16(s,\n\t\t\t bitmapData->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */\n\t\t\tStream_Read_UINT16(s, bitmapData->cbScanWidth); /* cbScanWidth (2 bytes) */\n\t\t\tStream_Read_UINT16(s,\n\t\t\t bitmapData->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */\n\t\t\tbitmapData->bitmapLength = bitmapData->cbCompMainBodySize;\n\t\t}", "\t\tbitmapData->compressed = TRUE;\n\t}\n\telse\n\t\tbitmapData->compressed = FALSE;", "\tif (Stream_GetRemainingLength(s) < bitmapData->bitmapLength)\n\t\treturn FALSE;", "\tif (bitmapData->bitmapLength > 0)\n\t{\n\t\tbitmapData->bitmapDataStream = malloc(bitmapData->bitmapLength);", "\t\tif (!bitmapData->bitmapDataStream)\n\t\t\treturn FALSE;", "\t\tmemcpy(bitmapData->bitmapDataStream, Stream_Pointer(s), bitmapData->bitmapLength);\n\t\tStream_Seek(s, bitmapData->bitmapLength);\n\t}", "\treturn TRUE;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 762, "char_start": 702, "chars": "if (Stream_GetRemainingLength(s) < 8)\n\t\t\t\treturn FALSE;\n\n\t\t\t" } ], "deleted": [] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/f8890a645c221823ac133dbf991f8a65ae50d637", "file_name": "libfreerdp/core/update.c", "func_name": "update_read_bitmap_data", "line_changes": { "added": [ { "char_end": 740, "char_start": 699, "line": "\t\t\tif (Stream_GetRemainingLength(s) < 8)\n", "line_no": 21 }, { "char_end": 758, "char_start": 740, "line": "\t\t\t\treturn FALSE;\n", "line_no": 22 }, { "char_end": 759, "char_start": 758, "line": "\n", "line_no": 23 } ], "deleted": [] }, "vul_type": "cwe-125" }
455
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static BOOL autodetect_recv_bandwidth_measure_results(rdpRdp* rdp, wStream* s,\n AUTODETECT_RSP_PDU* autodetectRspPdu)\n{\n\tBOOL success = TRUE;", "\tif (autodetectRspPdu->headerLength != 0x0E)\n\t\treturn FALSE;", "\tWLog_VRB(AUTODETECT_TAG, \"received Bandwidth Measure Results PDU\");", "", "\tStream_Read_UINT32(s, rdp->autodetect->bandwidthMeasureTimeDelta); /* timeDelta (4 bytes) */\n\tStream_Read_UINT32(s, rdp->autodetect->bandwidthMeasureByteCount); /* byteCount (4 bytes) */", "\tif (rdp->autodetect->bandwidthMeasureTimeDelta > 0)\n\t\trdp->autodetect->netCharBandwidth = rdp->autodetect->bandwidthMeasureByteCount * 8 /\n\t\t rdp->autodetect->bandwidthMeasureTimeDelta;\n\telse\n\t\trdp->autodetect->netCharBandwidth = 0;", "\tIFCALLRET(rdp->autodetect->BandwidthMeasureResults, success, rdp->context,\n\t autodetectRspPdu->sequenceNumber);\n\treturn success;\n}" ]
[ 1, 1, 1, 0, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 380, "char_start": 328, "chars": "if (Stream_GetRemainingLength(s) < 8)\n\t\treturn -1;\n\t" } ], "deleted": [] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/f5e73cc7c9cd973b516a618da877c87b80950b65", "file_name": "libfreerdp/core/autodetect.c", "func_name": "autodetect_recv_bandwidth_measure_results", "line_changes": { "added": [ { "char_end": 366, "char_start": 327, "line": "\tif (Stream_GetRemainingLength(s) < 8)\n", "line_no": 10 }, { "char_end": 379, "char_start": 366, "line": "\t\treturn -1;\n", "line_no": 11 } ], "deleted": [] }, "vul_type": "cwe-125" }
456
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static BOOL autodetect_recv_bandwidth_measure_results(rdpRdp* rdp, wStream* s,\n AUTODETECT_RSP_PDU* autodetectRspPdu)\n{\n\tBOOL success = TRUE;", "\tif (autodetectRspPdu->headerLength != 0x0E)\n\t\treturn FALSE;", "\tWLog_VRB(AUTODETECT_TAG, \"received Bandwidth Measure Results PDU\");", "\tif (Stream_GetRemainingLength(s) < 8)\n\t\treturn -1;", "\tStream_Read_UINT32(s, rdp->autodetect->bandwidthMeasureTimeDelta); /* timeDelta (4 bytes) */\n\tStream_Read_UINT32(s, rdp->autodetect->bandwidthMeasureByteCount); /* byteCount (4 bytes) */", "\tif (rdp->autodetect->bandwidthMeasureTimeDelta > 0)\n\t\trdp->autodetect->netCharBandwidth = rdp->autodetect->bandwidthMeasureByteCount * 8 /\n\t\t rdp->autodetect->bandwidthMeasureTimeDelta;\n\telse\n\t\trdp->autodetect->netCharBandwidth = 0;", "\tIFCALLRET(rdp->autodetect->BandwidthMeasureResults, success, rdp->context,\n\t autodetectRspPdu->sequenceNumber);\n\treturn success;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 380, "char_start": 328, "chars": "if (Stream_GetRemainingLength(s) < 8)\n\t\treturn -1;\n\t" } ], "deleted": [] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/f5e73cc7c9cd973b516a618da877c87b80950b65", "file_name": "libfreerdp/core/autodetect.c", "func_name": "autodetect_recv_bandwidth_measure_results", "line_changes": { "added": [ { "char_end": 366, "char_start": 327, "line": "\tif (Stream_GetRemainingLength(s) < 8)\n", "line_no": 10 }, { "char_end": 379, "char_start": 366, "line": "\t\treturn -1;\n", "line_no": 11 } ], "deleted": [] }, "vul_type": "cwe-125" }
456
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int ssl_parse_server_psk_hint( mbedtls_ssl_context *ssl,\n unsigned char **p,\n unsigned char *end )\n{\n int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;\n size_t len;\n ((void) ssl);", " /*\n * PSK parameters:\n *\n * opaque psk_identity_hint<0..2^16-1>;\n */\n if( (*p) > end - 2 )\n {\n MBEDTLS_SSL_DEBUG_MSG( 1, ( \"bad server key exchange message \"\n \"(psk_identity_hint length)\" ) );\n return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );\n }\n len = (*p)[0] << 8 | (*p)[1];\n *p += 2;\n", " if( (*p) + len > end )", " {\n MBEDTLS_SSL_DEBUG_MSG( 1, ( \"bad server key exchange message \"\n \"(psk_identity_hint length)\" ) );\n return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );\n }", " /*\n * Note: we currently ignore the PKS identity hint, as we only allow one\n * PSK to be provisionned on the client. This could be changed later if\n * someone needs that feature.\n */\n *p += len;\n ret = 0;", " return( ret );\n}" ]
[ 1, 1, 0, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 660, "char_start": 659, "chars": ">" }, { "char_end": 664, "char_start": 663, "chars": "d" }, { "char_end": 666, "char_start": 665, "chars": "-" }, { "char_end": 668, "char_start": 667, "chars": "l" } ], "deleted": [ { "char_end": 660, "char_start": 659, "chars": "+" }, { "char_end": 662, "char_start": 661, "chars": "l" }, { "char_end": 666, "char_start": 665, "chars": ">" }, { "char_end": 670, "char_start": 669, "chars": "d" } ] }, "commit_link": "github.com/ARMmbed/mbedtls/commit/5224a7544c95552553e2e6be0b4a789956a6464e", "file_name": "library/ssl_cli.c", "func_name": "ssl_parse_server_psk_hint", "line_changes": { "added": [ { "char_end": 673, "char_start": 646, "line": " if( (*p) > end - len )\n", "line_no": 23 } ], "deleted": [ { "char_end": 673, "char_start": 646, "line": " if( (*p) + len > end )\n", "line_no": 23 } ] }, "vul_type": "cwe-125" }
457
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int ssl_parse_server_psk_hint( mbedtls_ssl_context *ssl,\n unsigned char **p,\n unsigned char *end )\n{\n int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;\n size_t len;\n ((void) ssl);", " /*\n * PSK parameters:\n *\n * opaque psk_identity_hint<0..2^16-1>;\n */\n if( (*p) > end - 2 )\n {\n MBEDTLS_SSL_DEBUG_MSG( 1, ( \"bad server key exchange message \"\n \"(psk_identity_hint length)\" ) );\n return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );\n }\n len = (*p)[0] << 8 | (*p)[1];\n *p += 2;\n", " if( (*p) > end - len )", " {\n MBEDTLS_SSL_DEBUG_MSG( 1, ( \"bad server key exchange message \"\n \"(psk_identity_hint length)\" ) );\n return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );\n }", " /*\n * Note: we currently ignore the PKS identity hint, as we only allow one\n * PSK to be provisionned on the client. This could be changed later if\n * someone needs that feature.\n */\n *p += len;\n ret = 0;", " return( ret );\n}" ]
[ 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 660, "char_start": 659, "chars": ">" }, { "char_end": 664, "char_start": 663, "chars": "d" }, { "char_end": 666, "char_start": 665, "chars": "-" }, { "char_end": 668, "char_start": 667, "chars": "l" } ], "deleted": [ { "char_end": 660, "char_start": 659, "chars": "+" }, { "char_end": 662, "char_start": 661, "chars": "l" }, { "char_end": 666, "char_start": 665, "chars": ">" }, { "char_end": 670, "char_start": 669, "chars": "d" } ] }, "commit_link": "github.com/ARMmbed/mbedtls/commit/5224a7544c95552553e2e6be0b4a789956a6464e", "file_name": "library/ssl_cli.c", "func_name": "ssl_parse_server_psk_hint", "line_changes": { "added": [ { "char_end": 673, "char_start": 646, "line": " if( (*p) > end - len )\n", "line_no": 23 } ], "deleted": [ { "char_end": 673, "char_start": 646, "line": " if( (*p) + len > end )\n", "line_no": 23 } ] }, "vul_type": "cwe-125" }
457
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void youngcollection (lua_State *L, global_State *g) {\n GCObject **psurvival; /* to point to first non-dead survival object */\n lua_assert(g->gcstate == GCSpropagate);", " markold(g, g->survival, g->reallyold);", " markold(g, g->finobj, g->finobjrold);\n atomic(L);", " /* sweep nursery and get a pointer to its last live element */\n psurvival = sweepgen(L, g, &g->allgc, g->survival);\n /* sweep 'survival' and 'old' */\n sweepgen(L, g, psurvival, g->reallyold);\n g->reallyold = g->old;\n g->old = *psurvival; /* 'survival' survivals are old now */\n g->survival = g->allgc; /* all news are survivals */", " /* repeat for 'finobj' lists */\n psurvival = sweepgen(L, g, &g->finobj, g->finobjsur);\n /* sweep 'survival' and 'old' */\n sweepgen(L, g, psurvival, g->finobjrold);\n g->finobjrold = g->finobjold;\n g->finobjold = *psurvival; /* 'survival' survivals are old now */\n g->finobjsur = g->finobj; /* all news are survivals */", " sweepgen(L, g, &g->tobefnz, NULL);", " finishgencycle(L, g);\n}" ]
[ 1, 0, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 199, "char_start": 196, "chars": "lgc" } ], "deleted": [ { "char_end": 200, "char_start": 194, "chars": "surviv" } ] }, "commit_link": "github.com/lua/lua/commit/127e7a6c8942b362aa3c6627f44d660a4fb75312", "file_name": "lgc.c", "func_name": "youngcollection", "line_changes": { "added": [ { "char_end": 216, "char_start": 178, "line": " markold(g, g->allgc, g->reallyold);\n", "line_no": 4 } ], "deleted": [ { "char_end": 219, "char_start": 178, "line": " markold(g, g->survival, g->reallyold);\n", "line_no": 4 } ] }, "vul_type": "cwe-125" }
458
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void youngcollection (lua_State *L, global_State *g) {\n GCObject **psurvival; /* to point to first non-dead survival object */\n lua_assert(g->gcstate == GCSpropagate);", " markold(g, g->allgc, g->reallyold);", " markold(g, g->finobj, g->finobjrold);\n atomic(L);", " /* sweep nursery and get a pointer to its last live element */\n psurvival = sweepgen(L, g, &g->allgc, g->survival);\n /* sweep 'survival' and 'old' */\n sweepgen(L, g, psurvival, g->reallyold);\n g->reallyold = g->old;\n g->old = *psurvival; /* 'survival' survivals are old now */\n g->survival = g->allgc; /* all news are survivals */", " /* repeat for 'finobj' lists */\n psurvival = sweepgen(L, g, &g->finobj, g->finobjsur);\n /* sweep 'survival' and 'old' */\n sweepgen(L, g, psurvival, g->finobjrold);\n g->finobjrold = g->finobjold;\n g->finobjold = *psurvival; /* 'survival' survivals are old now */\n g->finobjsur = g->finobj; /* all news are survivals */", " sweepgen(L, g, &g->tobefnz, NULL);", " finishgencycle(L, g);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 199, "char_start": 196, "chars": "lgc" } ], "deleted": [ { "char_end": 200, "char_start": 194, "chars": "surviv" } ] }, "commit_link": "github.com/lua/lua/commit/127e7a6c8942b362aa3c6627f44d660a4fb75312", "file_name": "lgc.c", "func_name": "youngcollection", "line_changes": { "added": [ { "char_end": 216, "char_start": 178, "line": " markold(g, g->allgc, g->reallyold);\n", "line_no": 4 } ], "deleted": [ { "char_end": 219, "char_start": 178, "line": " markold(g, g->survival, g->reallyold);\n", "line_no": 4 } ] }, "vul_type": "cwe-125" }
458
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int ext4_fill_super(struct super_block *sb, void *data, int silent)\n{\n\tchar *orig_data = kstrdup(data, GFP_KERNEL);\n\tstruct buffer_head *bh;\n\tstruct ext4_super_block *es = NULL;\n\tstruct ext4_sb_info *sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);\n\text4_fsblk_t block;\n\text4_fsblk_t sb_block = get_sb_block(&data);\n\text4_fsblk_t logical_sb_block;\n\tunsigned long offset = 0;\n\tunsigned long journal_devnum = 0;\n\tunsigned long def_mount_opts;\n\tstruct inode *root;\n\tconst char *descr;\n\tint ret = -ENOMEM;\n\tint blocksize, clustersize;\n\tunsigned int db_count;\n\tunsigned int i;\n\tint needs_recovery, has_huge_files, has_bigalloc;\n\t__u64 blocks_count;\n\tint err = 0;\n\tunsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;\n\text4_group_t first_not_zeroed;", "\tif ((data && !orig_data) || !sbi)\n\t\tgoto out_free_base;", "\tsbi->s_blockgroup_lock =\n\t\tkzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);\n\tif (!sbi->s_blockgroup_lock)\n\t\tgoto out_free_base;", "\tsb->s_fs_info = sbi;\n\tsbi->s_sb = sb;\n\tsbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;\n\tsbi->s_sb_block = sb_block;\n\tif (sb->s_bdev->bd_part)\n\t\tsbi->s_sectors_written_start =\n\t\t\tpart_stat_read(sb->s_bdev->bd_part, sectors[1]);", "\t/* Cleanup superblock name */\n\tstrreplace(sb->s_id, '/', '!');", "\t/* -EINVAL is default */\n\tret = -EINVAL;\n\tblocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);\n\tif (!blocksize) {\n\t\text4_msg(sb, KERN_ERR, \"unable to set blocksize\");\n\t\tgoto out_fail;\n\t}", "\t/*\n\t * The ext4 superblock will not be buffer aligned for other than 1kB\n\t * block sizes. We need to calculate the offset from buffer start.\n\t */\n\tif (blocksize != EXT4_MIN_BLOCK_SIZE) {\n\t\tlogical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;\n\t\toffset = do_div(logical_sb_block, blocksize);\n\t} else {\n\t\tlogical_sb_block = sb_block;\n\t}", "\tif (!(bh = sb_bread_unmovable(sb, logical_sb_block))) {\n\t\text4_msg(sb, KERN_ERR, \"unable to read superblock\");\n\t\tgoto out_fail;\n\t}\n\t/*\n\t * Note: s_es must be initialized as soon as possible because\n\t * some ext4 macro-instructions depend on its value\n\t */\n\tes = (struct ext4_super_block *) (bh->b_data + offset);\n\tsbi->s_es = es;\n\tsb->s_magic = le16_to_cpu(es->s_magic);\n\tif (sb->s_magic != EXT4_SUPER_MAGIC)\n\t\tgoto cantfind_ext4;\n\tsbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);", "\t/* Warn if metadata_csum and gdt_csum are both set. */\n\tif (ext4_has_feature_metadata_csum(sb) &&\n\t ext4_has_feature_gdt_csum(sb))\n\t\text4_warning(sb, \"metadata_csum and uninit_bg are \"\n\t\t\t \"redundant flags; please run fsck.\");", "\t/* Check for a known checksum algorithm */\n\tif (!ext4_verify_csum_type(sb, es)) {\n\t\text4_msg(sb, KERN_ERR, \"VFS: Found ext4 filesystem with \"\n\t\t\t \"unknown checksum algorithm.\");\n\t\tsilent = 1;\n\t\tgoto cantfind_ext4;\n\t}", "\t/* Load the checksum driver */\n\tif (ext4_has_feature_metadata_csum(sb)) {\n\t\tsbi->s_chksum_driver = crypto_alloc_shash(\"crc32c\", 0, 0);\n\t\tif (IS_ERR(sbi->s_chksum_driver)) {\n\t\t\text4_msg(sb, KERN_ERR, \"Cannot load crc32c driver.\");\n\t\t\tret = PTR_ERR(sbi->s_chksum_driver);\n\t\t\tsbi->s_chksum_driver = NULL;\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\t/* Check superblock checksum */\n\tif (!ext4_superblock_csum_verify(sb, es)) {\n\t\text4_msg(sb, KERN_ERR, \"VFS: Found ext4 filesystem with \"\n\t\t\t \"invalid superblock checksum. Run e2fsck?\");\n\t\tsilent = 1;\n\t\tret = -EFSBADCRC;\n\t\tgoto cantfind_ext4;\n\t}", "\t/* Precompute checksum seed for all metadata */\n\tif (ext4_has_feature_csum_seed(sb))\n\t\tsbi->s_csum_seed = le32_to_cpu(es->s_checksum_seed);\n\telse if (ext4_has_metadata_csum(sb))\n\t\tsbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid,\n\t\t\t\t\t sizeof(es->s_uuid));", "\t/* Set defaults before we parse the mount options */\n\tdef_mount_opts = le32_to_cpu(es->s_default_mount_opts);\n\tset_opt(sb, INIT_INODE_TABLE);\n\tif (def_mount_opts & EXT4_DEFM_DEBUG)\n\t\tset_opt(sb, DEBUG);\n\tif (def_mount_opts & EXT4_DEFM_BSDGROUPS)\n\t\tset_opt(sb, GRPID);\n\tif (def_mount_opts & EXT4_DEFM_UID16)\n\t\tset_opt(sb, NO_UID32);\n\t/* xattr user namespace & acls are now defaulted on */\n\tset_opt(sb, XATTR_USER);\n#ifdef CONFIG_EXT4_FS_POSIX_ACL\n\tset_opt(sb, POSIX_ACL);\n#endif\n\t/* don't forget to enable journal_csum when metadata_csum is enabled. */\n\tif (ext4_has_metadata_csum(sb))\n\t\tset_opt(sb, JOURNAL_CHECKSUM);", "\tif ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)\n\t\tset_opt(sb, JOURNAL_DATA);\n\telse if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)\n\t\tset_opt(sb, ORDERED_DATA);\n\telse if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)\n\t\tset_opt(sb, WRITEBACK_DATA);", "\tif (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)\n\t\tset_opt(sb, ERRORS_PANIC);\n\telse if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE)\n\t\tset_opt(sb, ERRORS_CONT);\n\telse\n\t\tset_opt(sb, ERRORS_RO);\n\t/* block_validity enabled by default; disable with noblock_validity */\n\tset_opt(sb, BLOCK_VALIDITY);\n\tif (def_mount_opts & EXT4_DEFM_DISCARD)\n\t\tset_opt(sb, DISCARD);", "\tsbi->s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));\n\tsbi->s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));\n\tsbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;\n\tsbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;\n\tsbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;", "\tif ((def_mount_opts & EXT4_DEFM_NOBARRIER) == 0)\n\t\tset_opt(sb, BARRIER);", "\t/*\n\t * enable delayed allocation by default\n\t * Use -o nodelalloc to turn it off\n\t */\n\tif (!IS_EXT3_SB(sb) && !IS_EXT2_SB(sb) &&\n\t ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))\n\t\tset_opt(sb, DELALLOC);", "\t/*\n\t * set default s_li_wait_mult for lazyinit, for the case there is\n\t * no mount option specified.\n\t */\n\tsbi->s_li_wait_mult = EXT4_DEF_LI_WAIT_MULT;", "\tif (sbi->s_es->s_mount_opts[0]) {\n\t\tchar *s_mount_opts = kstrndup(sbi->s_es->s_mount_opts,\n\t\t\t\t\t sizeof(sbi->s_es->s_mount_opts),\n\t\t\t\t\t GFP_KERNEL);\n\t\tif (!s_mount_opts)\n\t\t\tgoto failed_mount;\n\t\tif (!parse_options(s_mount_opts, sb, &journal_devnum,\n\t\t\t\t &journal_ioprio, 0)) {\n\t\t\text4_msg(sb, KERN_WARNING,\n\t\t\t\t \"failed to parse options in superblock: %s\",\n\t\t\t\t s_mount_opts);\n\t\t}\n\t\tkfree(s_mount_opts);\n\t}\n\tsbi->s_def_mount_opt = sbi->s_mount_opt;\n\tif (!parse_options((char *) data, sb, &journal_devnum,\n\t\t\t &journal_ioprio, 0))\n\t\tgoto failed_mount;", "\tif (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {\n\t\tprintk_once(KERN_WARNING \"EXT4-fs: Warning: mounting \"\n\t\t\t \"with data=journal disables delayed \"\n\t\t\t \"allocation and O_DIRECT support!\\n\");\n\t\tif (test_opt2(sb, EXPLICIT_DELALLOC)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"both data=journal and delalloc\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (test_opt(sb, DIOREAD_NOLOCK)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"both data=journal and dioread_nolock\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (test_opt(sb, DAX)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"both data=journal and dax\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (test_opt(sb, DELALLOC))\n\t\t\tclear_opt(sb, DELALLOC);\n\t} else {\n\t\tsb->s_iflags |= SB_I_CGROUPWB;\n\t}", "\tsb->s_flags = (sb->s_flags & ~MS_POSIXACL) |\n\t\t(test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);", "\tif (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&\n\t (ext4_has_compat_features(sb) ||\n\t ext4_has_ro_compat_features(sb) ||\n\t ext4_has_incompat_features(sb)))\n\t\text4_msg(sb, KERN_WARNING,\n\t\t \"feature flags set on rev 0 fs, \"\n\t\t \"running e2fsck is recommended\");", "\tif (es->s_creator_os == cpu_to_le32(EXT4_OS_HURD)) {\n\t\tset_opt2(sb, HURD_COMPAT);\n\t\tif (ext4_has_feature_64bit(sb)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"The Hurd can't support 64-bit file systems\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\tif (IS_EXT2_SB(sb)) {\n\t\tif (ext2_feature_set_ok(sb))\n\t\t\text4_msg(sb, KERN_INFO, \"mounting ext2 file system \"\n\t\t\t\t \"using the ext4 subsystem\");\n\t\telse {\n\t\t\text4_msg(sb, KERN_ERR, \"couldn't mount as ext2 due \"\n\t\t\t\t \"to feature incompatibilities\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\tif (IS_EXT3_SB(sb)) {\n\t\tif (ext3_feature_set_ok(sb))\n\t\t\text4_msg(sb, KERN_INFO, \"mounting ext3 file system \"\n\t\t\t\t \"using the ext4 subsystem\");\n\t\telse {\n\t\t\text4_msg(sb, KERN_ERR, \"couldn't mount as ext3 due \"\n\t\t\t\t \"to feature incompatibilities\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\t/*\n\t * Check feature flags regardless of the revision level, since we\n\t * previously didn't change the revision level when setting the flags,\n\t * so there is a chance incompat flags are set on a rev 0 filesystem.\n\t */\n\tif (!ext4_feature_set_ok(sb, (sb->s_flags & MS_RDONLY)))\n\t\tgoto failed_mount;", "\tblocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);\n\tif (blocksize < EXT4_MIN_BLOCK_SIZE ||\n\t blocksize > EXT4_MAX_BLOCK_SIZE) {\n\t\text4_msg(sb, KERN_ERR,\n\t\t \"Unsupported filesystem blocksize %d (%d log_block_size)\",\n\t\t\t blocksize, le32_to_cpu(es->s_log_block_size));\n\t\tgoto failed_mount;\n\t}\n\tif (le32_to_cpu(es->s_log_block_size) >\n\t (EXT4_MAX_BLOCK_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {\n\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Invalid log block size: %u\",\n\t\t\t le32_to_cpu(es->s_log_block_size));\n\t\tgoto failed_mount;\n\t}", "\tif (le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) > (blocksize / 4)) {\n\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Number of reserved GDT blocks insanely large: %d\",\n\t\t\t le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks));\n\t\tgoto failed_mount;\n\t}", "\tif (sbi->s_mount_opt & EXT4_MOUNT_DAX) {\n\t\terr = bdev_dax_supported(sb, blocksize);\n\t\tif (err)\n\t\t\tgoto failed_mount;\n\t}", "\tif (ext4_has_feature_encrypt(sb) && es->s_encryption_level) {\n\t\text4_msg(sb, KERN_ERR, \"Unsupported encryption level %d\",\n\t\t\t es->s_encryption_level);\n\t\tgoto failed_mount;\n\t}", "\tif (sb->s_blocksize != blocksize) {\n\t\t/* Validate the filesystem blocksize */\n\t\tif (!sb_set_blocksize(sb, blocksize)) {\n\t\t\text4_msg(sb, KERN_ERR, \"bad block size %d\",\n\t\t\t\t\tblocksize);\n\t\t\tgoto failed_mount;\n\t\t}", "\t\tbrelse(bh);\n\t\tlogical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;\n\t\toffset = do_div(logical_sb_block, blocksize);\n\t\tbh = sb_bread_unmovable(sb, logical_sb_block);\n\t\tif (!bh) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Can't read superblock on 2nd try\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tes = (struct ext4_super_block *)(bh->b_data + offset);\n\t\tsbi->s_es = es;\n\t\tif (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Magic mismatch, very weird!\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\thas_huge_files = ext4_has_feature_huge_file(sb);\n\tsbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,\n\t\t\t\t\t\t has_huge_files);\n\tsb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);", "\tif (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {\n\t\tsbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;\n\t\tsbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;\n\t} else {\n\t\tsbi->s_inode_size = le16_to_cpu(es->s_inode_size);\n\t\tsbi->s_first_ino = le32_to_cpu(es->s_first_ino);\n\t\tif ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||\n\t\t (!is_power_of_2(sbi->s_inode_size)) ||\n\t\t (sbi->s_inode_size > blocksize)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"unsupported inode size: %d\",\n\t\t\t sbi->s_inode_size);\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)\n\t\t\tsb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);\n\t}", "\tsbi->s_desc_size = le16_to_cpu(es->s_desc_size);\n\tif (ext4_has_feature_64bit(sb)) {\n\t\tif (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||\n\t\t sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||\n\t\t !is_power_of_2(sbi->s_desc_size)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"unsupported descriptor size %lu\",\n\t\t\t sbi->s_desc_size);\n\t\t\tgoto failed_mount;\n\t\t}\n\t} else\n\t\tsbi->s_desc_size = EXT4_MIN_DESC_SIZE;", "\tsbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);\n\tsbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);", "\tsbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);\n\tif (sbi->s_inodes_per_block == 0)\n\t\tgoto cantfind_ext4;\n\tif (sbi->s_inodes_per_group < sbi->s_inodes_per_block ||\n\t sbi->s_inodes_per_group > blocksize * 8) {\n\t\text4_msg(sb, KERN_ERR, \"invalid inodes per group: %lu\\n\",\n\t\t\t sbi->s_blocks_per_group);\n\t\tgoto failed_mount;\n\t}\n\tsbi->s_itb_per_group = sbi->s_inodes_per_group /\n\t\t\t\t\tsbi->s_inodes_per_block;\n\tsbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);\n\tsbi->s_sbh = bh;\n\tsbi->s_mount_state = le16_to_cpu(es->s_state);\n\tsbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));\n\tsbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));", "\tfor (i = 0; i < 4; i++)\n\t\tsbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);\n\tsbi->s_def_hash_version = es->s_def_hash_version;\n\tif (ext4_has_feature_dir_index(sb)) {\n\t\ti = le32_to_cpu(es->s_flags);\n\t\tif (i & EXT2_FLAGS_UNSIGNED_HASH)\n\t\t\tsbi->s_hash_unsigned = 3;\n\t\telse if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {\n#ifdef __CHAR_UNSIGNED__\n\t\t\tif (!(sb->s_flags & MS_RDONLY))\n\t\t\t\tes->s_flags |=\n\t\t\t\t\tcpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);\n\t\t\tsbi->s_hash_unsigned = 3;\n#else\n\t\t\tif (!(sb->s_flags & MS_RDONLY))\n\t\t\t\tes->s_flags |=\n\t\t\t\t\tcpu_to_le32(EXT2_FLAGS_SIGNED_HASH);\n#endif\n\t\t}\n\t}", "\t/* Handle clustersize */\n\tclustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);\n\thas_bigalloc = ext4_has_feature_bigalloc(sb);\n\tif (has_bigalloc) {\n\t\tif (clustersize < blocksize) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"cluster size (%d) smaller than \"\n\t\t\t\t \"block size (%d)\", clustersize, blocksize);\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (le32_to_cpu(es->s_log_cluster_size) >\n\t\t (EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"Invalid log cluster size: %u\",\n\t\t\t\t le32_to_cpu(es->s_log_cluster_size));\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tsbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -\n\t\t\tle32_to_cpu(es->s_log_block_size);\n\t\tsbi->s_clusters_per_group =\n\t\t\tle32_to_cpu(es->s_clusters_per_group);\n\t\tif (sbi->s_clusters_per_group > blocksize * 8) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"#clusters per group too big: %lu\",\n\t\t\t\t sbi->s_clusters_per_group);\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (sbi->s_blocks_per_group !=\n\t\t (sbi->s_clusters_per_group * (clustersize / blocksize))) {\n\t\t\text4_msg(sb, KERN_ERR, \"blocks per group (%lu) and \"\n\t\t\t\t \"clusters per group (%lu) inconsistent\",\n\t\t\t\t sbi->s_blocks_per_group,\n\t\t\t\t sbi->s_clusters_per_group);\n\t\t\tgoto failed_mount;\n\t\t}\n\t} else {\n\t\tif (clustersize != blocksize) {\n\t\t\text4_warning(sb, \"fragment/cluster size (%d) != \"\n\t\t\t\t \"block size (%d)\", clustersize,\n\t\t\t\t blocksize);\n\t\t\tclustersize = blocksize;\n\t\t}\n\t\tif (sbi->s_blocks_per_group > blocksize * 8) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"#blocks per group too big: %lu\",\n\t\t\t\t sbi->s_blocks_per_group);\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tsbi->s_clusters_per_group = sbi->s_blocks_per_group;\n\t\tsbi->s_cluster_bits = 0;\n\t}\n\tsbi->s_cluster_ratio = clustersize / blocksize;", "\t/* Do we have standard group size of clustersize * 8 blocks ? */\n\tif (sbi->s_blocks_per_group == clustersize << 3)\n\t\tset_opt2(sb, STD_GROUP_SIZE);", "\t/*\n\t * Test whether we have more sectors than will fit in sector_t,\n\t * and whether the max offset is addressable by the page cache.\n\t */\n\terr = generic_check_addressable(sb->s_blocksize_bits,\n\t\t\t\t\text4_blocks_count(es));\n\tif (err) {\n\t\text4_msg(sb, KERN_ERR, \"filesystem\"\n\t\t\t \" too large to mount safely on this system\");\n\t\tif (sizeof(sector_t) < 8)\n\t\t\text4_msg(sb, KERN_WARNING, \"CONFIG_LBDAF not enabled\");\n\t\tgoto failed_mount;\n\t}", "\tif (EXT4_BLOCKS_PER_GROUP(sb) == 0)\n\t\tgoto cantfind_ext4;", "\t/* check blocks count against device size */\n\tblocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;\n\tif (blocks_count && ext4_blocks_count(es) > blocks_count) {\n\t\text4_msg(sb, KERN_WARNING, \"bad geometry: block count %llu \"\n\t\t \"exceeds size of device (%llu blocks)\",\n\t\t ext4_blocks_count(es), blocks_count);\n\t\tgoto failed_mount;\n\t}", "\t/*\n\t * It makes no sense for the first data block to be beyond the end\n\t * of the filesystem.\n\t */\n\tif (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) {\n\t\text4_msg(sb, KERN_WARNING, \"bad geometry: first data \"\n\t\t\t \"block %u is beyond end of filesystem (%llu)\",\n\t\t\t le32_to_cpu(es->s_first_data_block),\n\t\t\t ext4_blocks_count(es));\n\t\tgoto failed_mount;\n\t}\n\tblocks_count = (ext4_blocks_count(es) -\n\t\t\tle32_to_cpu(es->s_first_data_block) +\n\t\t\tEXT4_BLOCKS_PER_GROUP(sb) - 1);\n\tdo_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));\n\tif (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {\n\t\text4_msg(sb, KERN_WARNING, \"groups count too large: %u \"\n\t\t \"(block count %llu, first data block %u, \"\n\t\t \"blocks per group %lu)\", sbi->s_groups_count,\n\t\t ext4_blocks_count(es),\n\t\t le32_to_cpu(es->s_first_data_block),\n\t\t EXT4_BLOCKS_PER_GROUP(sb));\n\t\tgoto failed_mount;\n\t}\n\tsbi->s_groups_count = blocks_count;\n\tsbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count,\n\t\t\t(EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));\n\tdb_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /\n\t\t EXT4_DESC_PER_BLOCK(sb);", "", "\tsbi->s_group_desc = ext4_kvmalloc(db_count *\n\t\t\t\t\t sizeof(struct buffer_head *),\n\t\t\t\t\t GFP_KERNEL);\n\tif (sbi->s_group_desc == NULL) {\n\t\text4_msg(sb, KERN_ERR, \"not enough memory\");\n\t\tret = -ENOMEM;\n\t\tgoto failed_mount;\n\t}", "\tbgl_lock_init(sbi->s_blockgroup_lock);", "\tfor (i = 0; i < db_count; i++) {\n\t\tblock = descriptor_loc(sb, logical_sb_block, i);\n\t\tsbi->s_group_desc[i] = sb_bread_unmovable(sb, block);\n\t\tif (!sbi->s_group_desc[i]) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"can't read group descriptor %d\", i);\n\t\t\tdb_count = i;\n\t\t\tgoto failed_mount2;\n\t\t}\n\t}\n\tif (!ext4_check_descriptors(sb, logical_sb_block, &first_not_zeroed)) {\n\t\text4_msg(sb, KERN_ERR, \"group descriptors corrupted!\");\n\t\tret = -EFSCORRUPTED;\n\t\tgoto failed_mount2;\n\t}", "\tsbi->s_gdb_count = db_count;\n\tget_random_bytes(&sbi->s_next_generation, sizeof(u32));\n\tspin_lock_init(&sbi->s_next_gen_lock);", "\tsetup_timer(&sbi->s_err_report, print_daily_error_info,\n\t\t(unsigned long) sb);", "\t/* Register extent status tree shrinker */\n\tif (ext4_es_register_shrinker(sbi))\n\t\tgoto failed_mount3;", "\tsbi->s_stripe = ext4_get_stripe_size(sbi);\n\tsbi->s_extent_max_zeroout_kb = 32;", "\t/*\n\t * set up enough so that it can read an inode\n\t */\n\tsb->s_op = &ext4_sops;\n\tsb->s_export_op = &ext4_export_ops;\n\tsb->s_xattr = ext4_xattr_handlers;\n\tsb->s_cop = &ext4_cryptops;\n#ifdef CONFIG_QUOTA\n\tsb->dq_op = &ext4_quota_operations;\n\tif (ext4_has_feature_quota(sb))\n\t\tsb->s_qcop = &dquot_quotactl_sysfile_ops;\n\telse\n\t\tsb->s_qcop = &ext4_qctl_operations;\n\tsb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;\n#endif\n\tmemcpy(sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));", "\tINIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */\n\tmutex_init(&sbi->s_orphan_lock);", "\tsb->s_root = NULL;", "\tneeds_recovery = (es->s_last_orphan != 0 ||\n\t\t\t ext4_has_feature_journal_needs_recovery(sb));", "\tif (ext4_has_feature_mmp(sb) && !(sb->s_flags & MS_RDONLY))\n\t\tif (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))\n\t\t\tgoto failed_mount3a;", "\t/*\n\t * The first inode we look at is the journal inode. Don't try\n\t * root first: it may be modified in the journal!\n\t */\n\tif (!test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) {\n\t\tif (ext4_load_journal(sb, es, journal_devnum))\n\t\t\tgoto failed_mount3a;\n\t} else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&\n\t\t ext4_has_feature_journal_needs_recovery(sb)) {\n\t\text4_msg(sb, KERN_ERR, \"required journal recovery \"\n\t\t \"suppressed and not mounted read-only\");\n\t\tgoto failed_mount_wq;\n\t} else {\n\t\t/* Nojournal mode, all journal mount options are illegal */\n\t\tif (test_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"journal_checksum, fs mounted w/o journal\");\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\t\tif (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"journal_async_commit, fs mounted w/o journal\");\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\t\tif (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"commit=%lu, fs mounted w/o journal\",\n\t\t\t\t sbi->s_commit_interval / HZ);\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\t\tif (EXT4_MOUNT_DATA_FLAGS &\n\t\t (sbi->s_mount_opt ^ sbi->s_def_mount_opt)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"data=, fs mounted w/o journal\");\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\t\tsbi->s_def_mount_opt &= EXT4_MOUNT_JOURNAL_CHECKSUM;\n\t\tclear_opt(sb, JOURNAL_CHECKSUM);\n\t\tclear_opt(sb, DATA_FLAGS);\n\t\tsbi->s_journal = NULL;\n\t\tneeds_recovery = 0;\n\t\tgoto no_journal;\n\t}", "\tif (ext4_has_feature_64bit(sb) &&\n\t !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,\n\t\t\t\t JBD2_FEATURE_INCOMPAT_64BIT)) {\n\t\text4_msg(sb, KERN_ERR, \"Failed to set 64-bit journal feature\");\n\t\tgoto failed_mount_wq;\n\t}", "\tif (!set_journal_csum_feature_set(sb)) {\n\t\text4_msg(sb, KERN_ERR, \"Failed to set journal checksum \"\n\t\t\t \"feature set\");\n\t\tgoto failed_mount_wq;\n\t}", "\t/* We have now updated the journal if required, so we can\n\t * validate the data journaling mode. */\n\tswitch (test_opt(sb, DATA_FLAGS)) {\n\tcase 0:\n\t\t/* No mode set, assume a default based on the journal\n\t\t * capabilities: ORDERED_DATA if the journal can\n\t\t * cope, else JOURNAL_DATA\n\t\t */\n\t\tif (jbd2_journal_check_available_features\n\t\t (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE))\n\t\t\tset_opt(sb, ORDERED_DATA);\n\t\telse\n\t\t\tset_opt(sb, JOURNAL_DATA);\n\t\tbreak;", "\tcase EXT4_MOUNT_ORDERED_DATA:\n\tcase EXT4_MOUNT_WRITEBACK_DATA:\n\t\tif (!jbd2_journal_check_available_features\n\t\t (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {\n\t\t\text4_msg(sb, KERN_ERR, \"Journal does not support \"\n\t\t\t \"requested data journaling mode\");\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\tdefault:\n\t\tbreak;\n\t}\n\tset_task_ioprio(sbi->s_journal->j_task, journal_ioprio);", "\tsbi->s_journal->j_commit_callback = ext4_journal_commit_callback;", "no_journal:\n\tsbi->s_mb_cache = ext4_xattr_create_cache();\n\tif (!sbi->s_mb_cache) {\n\t\text4_msg(sb, KERN_ERR, \"Failed to create an mb_cache\");\n\t\tgoto failed_mount_wq;\n\t}", "\tif ((DUMMY_ENCRYPTION_ENABLED(sbi) || ext4_has_feature_encrypt(sb)) &&\n\t (blocksize != PAGE_SIZE)) {\n\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Unsupported blocksize for fs encryption\");\n\t\tgoto failed_mount_wq;\n\t}", "\tif (DUMMY_ENCRYPTION_ENABLED(sbi) && !(sb->s_flags & MS_RDONLY) &&\n\t !ext4_has_feature_encrypt(sb)) {\n\t\text4_set_feature_encrypt(sb);\n\t\text4_commit_super(sb, 1);\n\t}", "\t/*\n\t * Get the # of file system overhead blocks from the\n\t * superblock if present.\n\t */\n\tif (es->s_overhead_clusters)\n\t\tsbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);\n\telse {\n\t\terr = ext4_calculate_overhead(sb);\n\t\tif (err)\n\t\t\tgoto failed_mount_wq;\n\t}", "\t/*\n\t * The maximum number of concurrent works can be high and\n\t * concurrency isn't really necessary. Limit it to 1.\n\t */\n\tEXT4_SB(sb)->rsv_conversion_wq =\n\t\talloc_workqueue(\"ext4-rsv-conversion\", WQ_MEM_RECLAIM | WQ_UNBOUND, 1);\n\tif (!EXT4_SB(sb)->rsv_conversion_wq) {\n\t\tprintk(KERN_ERR \"EXT4-fs: failed to create workqueue\\n\");\n\t\tret = -ENOMEM;\n\t\tgoto failed_mount4;\n\t}", "\t/*\n\t * The jbd2_journal_load will have done any necessary log recovery,\n\t * so we can safely mount the rest of the filesystem now.\n\t */", "\troot = ext4_iget(sb, EXT4_ROOT_INO);\n\tif (IS_ERR(root)) {\n\t\text4_msg(sb, KERN_ERR, \"get root inode failed\");\n\t\tret = PTR_ERR(root);\n\t\troot = NULL;\n\t\tgoto failed_mount4;\n\t}\n\tif (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {\n\t\text4_msg(sb, KERN_ERR, \"corrupt root inode, run e2fsck\");\n\t\tiput(root);\n\t\tgoto failed_mount4;\n\t}\n\tsb->s_root = d_make_root(root);\n\tif (!sb->s_root) {\n\t\text4_msg(sb, KERN_ERR, \"get root dentry failed\");\n\t\tret = -ENOMEM;\n\t\tgoto failed_mount4;\n\t}", "\tif (ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY))\n\t\tsb->s_flags |= MS_RDONLY;", "\t/* determine the minimum size of new large inodes, if present */\n\tif (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {\n\t\tsbi->s_want_extra_isize = sizeof(struct ext4_inode) -\n\t\t\t\t\t\t EXT4_GOOD_OLD_INODE_SIZE;\n\t\tif (ext4_has_feature_extra_isize(sb)) {\n\t\t\tif (sbi->s_want_extra_isize <\n\t\t\t le16_to_cpu(es->s_want_extra_isize))\n\t\t\t\tsbi->s_want_extra_isize =\n\t\t\t\t\tle16_to_cpu(es->s_want_extra_isize);\n\t\t\tif (sbi->s_want_extra_isize <\n\t\t\t le16_to_cpu(es->s_min_extra_isize))\n\t\t\t\tsbi->s_want_extra_isize =\n\t\t\t\t\tle16_to_cpu(es->s_min_extra_isize);\n\t\t}\n\t}\n\t/* Check if enough inode space is available */\n\tif (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >\n\t\t\t\t\t\t\tsbi->s_inode_size) {\n\t\tsbi->s_want_extra_isize = sizeof(struct ext4_inode) -\n\t\t\t\t\t\t EXT4_GOOD_OLD_INODE_SIZE;\n\t\text4_msg(sb, KERN_INFO, \"required extra inode space not\"\n\t\t\t \"available\");\n\t}", "\text4_set_resv_clusters(sb);", "\terr = ext4_setup_system_zone(sb);\n\tif (err) {\n\t\text4_msg(sb, KERN_ERR, \"failed to initialize system \"\n\t\t\t \"zone (%d)\", err);\n\t\tgoto failed_mount4a;\n\t}", "\text4_ext_init(sb);\n\terr = ext4_mb_init(sb);\n\tif (err) {\n\t\text4_msg(sb, KERN_ERR, \"failed to initialize mballoc (%d)\",\n\t\t\t err);\n\t\tgoto failed_mount5;\n\t}", "\tblock = ext4_count_free_clusters(sb);\n\text4_free_blocks_count_set(sbi->s_es, \n\t\t\t\t EXT4_C2B(sbi, block));\n\terr = percpu_counter_init(&sbi->s_freeclusters_counter, block,\n\t\t\t\t GFP_KERNEL);\n\tif (!err) {\n\t\tunsigned long freei = ext4_count_free_inodes(sb);\n\t\tsbi->s_es->s_free_inodes_count = cpu_to_le32(freei);\n\t\terr = percpu_counter_init(&sbi->s_freeinodes_counter, freei,\n\t\t\t\t\t GFP_KERNEL);\n\t}\n\tif (!err)\n\t\terr = percpu_counter_init(&sbi->s_dirs_counter,\n\t\t\t\t\t ext4_count_dirs(sb), GFP_KERNEL);\n\tif (!err)\n\t\terr = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0,\n\t\t\t\t\t GFP_KERNEL);\n\tif (!err)\n\t\terr = percpu_init_rwsem(&sbi->s_journal_flag_rwsem);", "\tif (err) {\n\t\text4_msg(sb, KERN_ERR, \"insufficient memory\");\n\t\tgoto failed_mount6;\n\t}", "\tif (ext4_has_feature_flex_bg(sb))\n\t\tif (!ext4_fill_flex_info(sb)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"unable to initialize \"\n\t\t\t \"flex_bg meta info!\");\n\t\t\tgoto failed_mount6;\n\t\t}", "\terr = ext4_register_li_request(sb, first_not_zeroed);\n\tif (err)\n\t\tgoto failed_mount6;", "\terr = ext4_register_sysfs(sb);\n\tif (err)\n\t\tgoto failed_mount7;", "#ifdef CONFIG_QUOTA\n\t/* Enable quota usage during mount. */\n\tif (ext4_has_feature_quota(sb) && !(sb->s_flags & MS_RDONLY)) {\n\t\terr = ext4_enable_quotas(sb);\n\t\tif (err)\n\t\t\tgoto failed_mount8;\n\t}\n#endif /* CONFIG_QUOTA */", "\tEXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;\n\text4_orphan_cleanup(sb, es);\n\tEXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;\n\tif (needs_recovery) {\n\t\text4_msg(sb, KERN_INFO, \"recovery complete\");\n\t\text4_mark_recovery_complete(sb, es);\n\t}\n\tif (EXT4_SB(sb)->s_journal) {\n\t\tif (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)\n\t\t\tdescr = \" journalled data mode\";\n\t\telse if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)\n\t\t\tdescr = \" ordered data mode\";\n\t\telse\n\t\t\tdescr = \" writeback data mode\";\n\t} else\n\t\tdescr = \"out journal\";", "\tif (test_opt(sb, DISCARD)) {\n\t\tstruct request_queue *q = bdev_get_queue(sb->s_bdev);\n\t\tif (!blk_queue_discard(q))\n\t\t\text4_msg(sb, KERN_WARNING,\n\t\t\t\t \"mounting with \\\"discard\\\" option, but \"\n\t\t\t\t \"the device does not support discard\");\n\t}", "\tif (___ratelimit(&ext4_mount_msg_ratelimit, \"EXT4-fs mount\"))\n\t\text4_msg(sb, KERN_INFO, \"mounted filesystem with%s. \"\n\t\t\t \"Opts: %.*s%s%s\", descr,\n\t\t\t (int) sizeof(sbi->s_es->s_mount_opts),\n\t\t\t sbi->s_es->s_mount_opts,\n\t\t\t *sbi->s_es->s_mount_opts ? \"; \" : \"\", orig_data);", "\tif (es->s_error_count)\n\t\tmod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */", "\t/* Enable message ratelimiting. Default is 10 messages per 5 secs. */\n\tratelimit_state_init(&sbi->s_err_ratelimit_state, 5 * HZ, 10);\n\tratelimit_state_init(&sbi->s_warning_ratelimit_state, 5 * HZ, 10);\n\tratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10);", "\tkfree(orig_data);\n#ifdef CONFIG_EXT4_FS_ENCRYPTION\n\tmemcpy(sbi->key_prefix, EXT4_KEY_DESC_PREFIX,\n\t\t\t\tEXT4_KEY_DESC_PREFIX_SIZE);\n\tsbi->key_prefix_size = EXT4_KEY_DESC_PREFIX_SIZE;\n#endif\n\treturn 0;", "cantfind_ext4:\n\tif (!silent)\n\t\text4_msg(sb, KERN_ERR, \"VFS: Can't find ext4 filesystem\");\n\tgoto failed_mount;", "#ifdef CONFIG_QUOTA\nfailed_mount8:\n\text4_unregister_sysfs(sb);\n#endif\nfailed_mount7:\n\text4_unregister_li_request(sb);\nfailed_mount6:\n\text4_mb_release(sb);\n\tif (sbi->s_flex_groups)\n\t\tkvfree(sbi->s_flex_groups);\n\tpercpu_counter_destroy(&sbi->s_freeclusters_counter);\n\tpercpu_counter_destroy(&sbi->s_freeinodes_counter);\n\tpercpu_counter_destroy(&sbi->s_dirs_counter);\n\tpercpu_counter_destroy(&sbi->s_dirtyclusters_counter);\nfailed_mount5:\n\text4_ext_release(sb);\n\text4_release_system_zone(sb);\nfailed_mount4a:\n\tdput(sb->s_root);\n\tsb->s_root = NULL;\nfailed_mount4:\n\text4_msg(sb, KERN_ERR, \"mount failed\");\n\tif (EXT4_SB(sb)->rsv_conversion_wq)\n\t\tdestroy_workqueue(EXT4_SB(sb)->rsv_conversion_wq);\nfailed_mount_wq:\n\tif (sbi->s_mb_cache) {\n\t\text4_xattr_destroy_cache(sbi->s_mb_cache);\n\t\tsbi->s_mb_cache = NULL;\n\t}\n\tif (sbi->s_journal) {\n\t\tjbd2_journal_destroy(sbi->s_journal);\n\t\tsbi->s_journal = NULL;\n\t}\nfailed_mount3a:\n\text4_es_unregister_shrinker(sbi);\nfailed_mount3:\n\tdel_timer_sync(&sbi->s_err_report);\n\tif (sbi->s_mmp_tsk)\n\t\tkthread_stop(sbi->s_mmp_tsk);\nfailed_mount2:\n\tfor (i = 0; i < db_count; i++)\n\t\tbrelse(sbi->s_group_desc[i]);\n\tkvfree(sbi->s_group_desc);\nfailed_mount:\n\tif (sbi->s_chksum_driver)\n\t\tcrypto_free_shash(sbi->s_chksum_driver);\n#ifdef CONFIG_QUOTA\n\tfor (i = 0; i < EXT4_MAXQUOTAS; i++)\n\t\tkfree(sbi->s_qf_names[i]);\n#endif\n\text4_blkdev_remove(sbi);\n\tbrelse(bh);\nout_fail:\n\tsb->s_fs_info = NULL;\n\tkfree(sbi->s_blockgroup_lock);\nout_free_base:\n\tkfree(sbi);\n\tkfree(orig_data);\n\treturn err ? err : ret;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 16999, "char_start": 16712, "chars": "if (ext4_has_feature_meta_bg(sb)) {\n\t\tif (le32_to_cpu(es->s_first_meta_bg) >= db_count) {\n\t\t\text4_msg(sb, KERN_WARNING,\n\t\t\t\t \"first meta block group too large: %u \"\n\t\t\t\t \"(group descriptor block count %u)\",\n\t\t\t\t le32_to_cpu(es->s_first_meta_bg), db_count);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\t" } ], "deleted": [] }, "commit_link": "github.com/torvalds/linux/commit/3a4b77cd47bb837b8557595ec7425f281f2ca1fe", "file_name": "fs/ext4/super.c", "func_name": "ext4_fill_super", "line_changes": { "added": [ { "char_end": 16748, "char_start": 16711, "line": "\tif (ext4_has_feature_meta_bg(sb)) {\n", "line_no": 522 }, { "char_end": 16802, "char_start": 16748, "line": "\t\tif (le32_to_cpu(es->s_first_meta_bg) >= db_count) {\n", "line_no": 523 }, { "char_end": 16832, "char_start": 16802, "line": "\t\t\text4_msg(sb, KERN_WARNING,\n", "line_no": 524 }, { "char_end": 16877, "char_start": 16832, "line": "\t\t\t\t \"first meta block group too large: %u \"\n", "line_no": 525 }, { "char_end": 16919, "char_start": 16877, "line": "\t\t\t\t \"(group descriptor block count %u)\",\n", "line_no": 526 }, { "char_end": 16969, "char_start": 16919, "line": "\t\t\t\t le32_to_cpu(es->s_first_meta_bg), db_count);\n", "line_no": 527 }, { "char_end": 16991, "char_start": 16969, "line": "\t\t\tgoto failed_mount;\n", "line_no": 528 }, { "char_end": 16995, "char_start": 16991, "line": "\t\t}\n", "line_no": 529 }, { "char_end": 16998, "char_start": 16995, "line": "\t}\n", "line_no": 530 } ], "deleted": [] }, "vul_type": "cwe-125" }
459
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int ext4_fill_super(struct super_block *sb, void *data, int silent)\n{\n\tchar *orig_data = kstrdup(data, GFP_KERNEL);\n\tstruct buffer_head *bh;\n\tstruct ext4_super_block *es = NULL;\n\tstruct ext4_sb_info *sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);\n\text4_fsblk_t block;\n\text4_fsblk_t sb_block = get_sb_block(&data);\n\text4_fsblk_t logical_sb_block;\n\tunsigned long offset = 0;\n\tunsigned long journal_devnum = 0;\n\tunsigned long def_mount_opts;\n\tstruct inode *root;\n\tconst char *descr;\n\tint ret = -ENOMEM;\n\tint blocksize, clustersize;\n\tunsigned int db_count;\n\tunsigned int i;\n\tint needs_recovery, has_huge_files, has_bigalloc;\n\t__u64 blocks_count;\n\tint err = 0;\n\tunsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;\n\text4_group_t first_not_zeroed;", "\tif ((data && !orig_data) || !sbi)\n\t\tgoto out_free_base;", "\tsbi->s_blockgroup_lock =\n\t\tkzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);\n\tif (!sbi->s_blockgroup_lock)\n\t\tgoto out_free_base;", "\tsb->s_fs_info = sbi;\n\tsbi->s_sb = sb;\n\tsbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;\n\tsbi->s_sb_block = sb_block;\n\tif (sb->s_bdev->bd_part)\n\t\tsbi->s_sectors_written_start =\n\t\t\tpart_stat_read(sb->s_bdev->bd_part, sectors[1]);", "\t/* Cleanup superblock name */\n\tstrreplace(sb->s_id, '/', '!');", "\t/* -EINVAL is default */\n\tret = -EINVAL;\n\tblocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);\n\tif (!blocksize) {\n\t\text4_msg(sb, KERN_ERR, \"unable to set blocksize\");\n\t\tgoto out_fail;\n\t}", "\t/*\n\t * The ext4 superblock will not be buffer aligned for other than 1kB\n\t * block sizes. We need to calculate the offset from buffer start.\n\t */\n\tif (blocksize != EXT4_MIN_BLOCK_SIZE) {\n\t\tlogical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;\n\t\toffset = do_div(logical_sb_block, blocksize);\n\t} else {\n\t\tlogical_sb_block = sb_block;\n\t}", "\tif (!(bh = sb_bread_unmovable(sb, logical_sb_block))) {\n\t\text4_msg(sb, KERN_ERR, \"unable to read superblock\");\n\t\tgoto out_fail;\n\t}\n\t/*\n\t * Note: s_es must be initialized as soon as possible because\n\t * some ext4 macro-instructions depend on its value\n\t */\n\tes = (struct ext4_super_block *) (bh->b_data + offset);\n\tsbi->s_es = es;\n\tsb->s_magic = le16_to_cpu(es->s_magic);\n\tif (sb->s_magic != EXT4_SUPER_MAGIC)\n\t\tgoto cantfind_ext4;\n\tsbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);", "\t/* Warn if metadata_csum and gdt_csum are both set. */\n\tif (ext4_has_feature_metadata_csum(sb) &&\n\t ext4_has_feature_gdt_csum(sb))\n\t\text4_warning(sb, \"metadata_csum and uninit_bg are \"\n\t\t\t \"redundant flags; please run fsck.\");", "\t/* Check for a known checksum algorithm */\n\tif (!ext4_verify_csum_type(sb, es)) {\n\t\text4_msg(sb, KERN_ERR, \"VFS: Found ext4 filesystem with \"\n\t\t\t \"unknown checksum algorithm.\");\n\t\tsilent = 1;\n\t\tgoto cantfind_ext4;\n\t}", "\t/* Load the checksum driver */\n\tif (ext4_has_feature_metadata_csum(sb)) {\n\t\tsbi->s_chksum_driver = crypto_alloc_shash(\"crc32c\", 0, 0);\n\t\tif (IS_ERR(sbi->s_chksum_driver)) {\n\t\t\text4_msg(sb, KERN_ERR, \"Cannot load crc32c driver.\");\n\t\t\tret = PTR_ERR(sbi->s_chksum_driver);\n\t\t\tsbi->s_chksum_driver = NULL;\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\t/* Check superblock checksum */\n\tif (!ext4_superblock_csum_verify(sb, es)) {\n\t\text4_msg(sb, KERN_ERR, \"VFS: Found ext4 filesystem with \"\n\t\t\t \"invalid superblock checksum. Run e2fsck?\");\n\t\tsilent = 1;\n\t\tret = -EFSBADCRC;\n\t\tgoto cantfind_ext4;\n\t}", "\t/* Precompute checksum seed for all metadata */\n\tif (ext4_has_feature_csum_seed(sb))\n\t\tsbi->s_csum_seed = le32_to_cpu(es->s_checksum_seed);\n\telse if (ext4_has_metadata_csum(sb))\n\t\tsbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid,\n\t\t\t\t\t sizeof(es->s_uuid));", "\t/* Set defaults before we parse the mount options */\n\tdef_mount_opts = le32_to_cpu(es->s_default_mount_opts);\n\tset_opt(sb, INIT_INODE_TABLE);\n\tif (def_mount_opts & EXT4_DEFM_DEBUG)\n\t\tset_opt(sb, DEBUG);\n\tif (def_mount_opts & EXT4_DEFM_BSDGROUPS)\n\t\tset_opt(sb, GRPID);\n\tif (def_mount_opts & EXT4_DEFM_UID16)\n\t\tset_opt(sb, NO_UID32);\n\t/* xattr user namespace & acls are now defaulted on */\n\tset_opt(sb, XATTR_USER);\n#ifdef CONFIG_EXT4_FS_POSIX_ACL\n\tset_opt(sb, POSIX_ACL);\n#endif\n\t/* don't forget to enable journal_csum when metadata_csum is enabled. */\n\tif (ext4_has_metadata_csum(sb))\n\t\tset_opt(sb, JOURNAL_CHECKSUM);", "\tif ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)\n\t\tset_opt(sb, JOURNAL_DATA);\n\telse if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)\n\t\tset_opt(sb, ORDERED_DATA);\n\telse if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)\n\t\tset_opt(sb, WRITEBACK_DATA);", "\tif (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)\n\t\tset_opt(sb, ERRORS_PANIC);\n\telse if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE)\n\t\tset_opt(sb, ERRORS_CONT);\n\telse\n\t\tset_opt(sb, ERRORS_RO);\n\t/* block_validity enabled by default; disable with noblock_validity */\n\tset_opt(sb, BLOCK_VALIDITY);\n\tif (def_mount_opts & EXT4_DEFM_DISCARD)\n\t\tset_opt(sb, DISCARD);", "\tsbi->s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));\n\tsbi->s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));\n\tsbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;\n\tsbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;\n\tsbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;", "\tif ((def_mount_opts & EXT4_DEFM_NOBARRIER) == 0)\n\t\tset_opt(sb, BARRIER);", "\t/*\n\t * enable delayed allocation by default\n\t * Use -o nodelalloc to turn it off\n\t */\n\tif (!IS_EXT3_SB(sb) && !IS_EXT2_SB(sb) &&\n\t ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))\n\t\tset_opt(sb, DELALLOC);", "\t/*\n\t * set default s_li_wait_mult for lazyinit, for the case there is\n\t * no mount option specified.\n\t */\n\tsbi->s_li_wait_mult = EXT4_DEF_LI_WAIT_MULT;", "\tif (sbi->s_es->s_mount_opts[0]) {\n\t\tchar *s_mount_opts = kstrndup(sbi->s_es->s_mount_opts,\n\t\t\t\t\t sizeof(sbi->s_es->s_mount_opts),\n\t\t\t\t\t GFP_KERNEL);\n\t\tif (!s_mount_opts)\n\t\t\tgoto failed_mount;\n\t\tif (!parse_options(s_mount_opts, sb, &journal_devnum,\n\t\t\t\t &journal_ioprio, 0)) {\n\t\t\text4_msg(sb, KERN_WARNING,\n\t\t\t\t \"failed to parse options in superblock: %s\",\n\t\t\t\t s_mount_opts);\n\t\t}\n\t\tkfree(s_mount_opts);\n\t}\n\tsbi->s_def_mount_opt = sbi->s_mount_opt;\n\tif (!parse_options((char *) data, sb, &journal_devnum,\n\t\t\t &journal_ioprio, 0))\n\t\tgoto failed_mount;", "\tif (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {\n\t\tprintk_once(KERN_WARNING \"EXT4-fs: Warning: mounting \"\n\t\t\t \"with data=journal disables delayed \"\n\t\t\t \"allocation and O_DIRECT support!\\n\");\n\t\tif (test_opt2(sb, EXPLICIT_DELALLOC)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"both data=journal and delalloc\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (test_opt(sb, DIOREAD_NOLOCK)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"both data=journal and dioread_nolock\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (test_opt(sb, DAX)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"both data=journal and dax\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (test_opt(sb, DELALLOC))\n\t\t\tclear_opt(sb, DELALLOC);\n\t} else {\n\t\tsb->s_iflags |= SB_I_CGROUPWB;\n\t}", "\tsb->s_flags = (sb->s_flags & ~MS_POSIXACL) |\n\t\t(test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);", "\tif (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&\n\t (ext4_has_compat_features(sb) ||\n\t ext4_has_ro_compat_features(sb) ||\n\t ext4_has_incompat_features(sb)))\n\t\text4_msg(sb, KERN_WARNING,\n\t\t \"feature flags set on rev 0 fs, \"\n\t\t \"running e2fsck is recommended\");", "\tif (es->s_creator_os == cpu_to_le32(EXT4_OS_HURD)) {\n\t\tset_opt2(sb, HURD_COMPAT);\n\t\tif (ext4_has_feature_64bit(sb)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"The Hurd can't support 64-bit file systems\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\tif (IS_EXT2_SB(sb)) {\n\t\tif (ext2_feature_set_ok(sb))\n\t\t\text4_msg(sb, KERN_INFO, \"mounting ext2 file system \"\n\t\t\t\t \"using the ext4 subsystem\");\n\t\telse {\n\t\t\text4_msg(sb, KERN_ERR, \"couldn't mount as ext2 due \"\n\t\t\t\t \"to feature incompatibilities\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\tif (IS_EXT3_SB(sb)) {\n\t\tif (ext3_feature_set_ok(sb))\n\t\t\text4_msg(sb, KERN_INFO, \"mounting ext3 file system \"\n\t\t\t\t \"using the ext4 subsystem\");\n\t\telse {\n\t\t\text4_msg(sb, KERN_ERR, \"couldn't mount as ext3 due \"\n\t\t\t\t \"to feature incompatibilities\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\t/*\n\t * Check feature flags regardless of the revision level, since we\n\t * previously didn't change the revision level when setting the flags,\n\t * so there is a chance incompat flags are set on a rev 0 filesystem.\n\t */\n\tif (!ext4_feature_set_ok(sb, (sb->s_flags & MS_RDONLY)))\n\t\tgoto failed_mount;", "\tblocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);\n\tif (blocksize < EXT4_MIN_BLOCK_SIZE ||\n\t blocksize > EXT4_MAX_BLOCK_SIZE) {\n\t\text4_msg(sb, KERN_ERR,\n\t\t \"Unsupported filesystem blocksize %d (%d log_block_size)\",\n\t\t\t blocksize, le32_to_cpu(es->s_log_block_size));\n\t\tgoto failed_mount;\n\t}\n\tif (le32_to_cpu(es->s_log_block_size) >\n\t (EXT4_MAX_BLOCK_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {\n\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Invalid log block size: %u\",\n\t\t\t le32_to_cpu(es->s_log_block_size));\n\t\tgoto failed_mount;\n\t}", "\tif (le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) > (blocksize / 4)) {\n\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Number of reserved GDT blocks insanely large: %d\",\n\t\t\t le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks));\n\t\tgoto failed_mount;\n\t}", "\tif (sbi->s_mount_opt & EXT4_MOUNT_DAX) {\n\t\terr = bdev_dax_supported(sb, blocksize);\n\t\tif (err)\n\t\t\tgoto failed_mount;\n\t}", "\tif (ext4_has_feature_encrypt(sb) && es->s_encryption_level) {\n\t\text4_msg(sb, KERN_ERR, \"Unsupported encryption level %d\",\n\t\t\t es->s_encryption_level);\n\t\tgoto failed_mount;\n\t}", "\tif (sb->s_blocksize != blocksize) {\n\t\t/* Validate the filesystem blocksize */\n\t\tif (!sb_set_blocksize(sb, blocksize)) {\n\t\t\text4_msg(sb, KERN_ERR, \"bad block size %d\",\n\t\t\t\t\tblocksize);\n\t\t\tgoto failed_mount;\n\t\t}", "\t\tbrelse(bh);\n\t\tlogical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;\n\t\toffset = do_div(logical_sb_block, blocksize);\n\t\tbh = sb_bread_unmovable(sb, logical_sb_block);\n\t\tif (!bh) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Can't read superblock on 2nd try\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tes = (struct ext4_super_block *)(bh->b_data + offset);\n\t\tsbi->s_es = es;\n\t\tif (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Magic mismatch, very weird!\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\thas_huge_files = ext4_has_feature_huge_file(sb);\n\tsbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,\n\t\t\t\t\t\t has_huge_files);\n\tsb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);", "\tif (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {\n\t\tsbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;\n\t\tsbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;\n\t} else {\n\t\tsbi->s_inode_size = le16_to_cpu(es->s_inode_size);\n\t\tsbi->s_first_ino = le32_to_cpu(es->s_first_ino);\n\t\tif ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||\n\t\t (!is_power_of_2(sbi->s_inode_size)) ||\n\t\t (sbi->s_inode_size > blocksize)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"unsupported inode size: %d\",\n\t\t\t sbi->s_inode_size);\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)\n\t\t\tsb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);\n\t}", "\tsbi->s_desc_size = le16_to_cpu(es->s_desc_size);\n\tif (ext4_has_feature_64bit(sb)) {\n\t\tif (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||\n\t\t sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||\n\t\t !is_power_of_2(sbi->s_desc_size)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"unsupported descriptor size %lu\",\n\t\t\t sbi->s_desc_size);\n\t\t\tgoto failed_mount;\n\t\t}\n\t} else\n\t\tsbi->s_desc_size = EXT4_MIN_DESC_SIZE;", "\tsbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);\n\tsbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);", "\tsbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);\n\tif (sbi->s_inodes_per_block == 0)\n\t\tgoto cantfind_ext4;\n\tif (sbi->s_inodes_per_group < sbi->s_inodes_per_block ||\n\t sbi->s_inodes_per_group > blocksize * 8) {\n\t\text4_msg(sb, KERN_ERR, \"invalid inodes per group: %lu\\n\",\n\t\t\t sbi->s_blocks_per_group);\n\t\tgoto failed_mount;\n\t}\n\tsbi->s_itb_per_group = sbi->s_inodes_per_group /\n\t\t\t\t\tsbi->s_inodes_per_block;\n\tsbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);\n\tsbi->s_sbh = bh;\n\tsbi->s_mount_state = le16_to_cpu(es->s_state);\n\tsbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));\n\tsbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));", "\tfor (i = 0; i < 4; i++)\n\t\tsbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);\n\tsbi->s_def_hash_version = es->s_def_hash_version;\n\tif (ext4_has_feature_dir_index(sb)) {\n\t\ti = le32_to_cpu(es->s_flags);\n\t\tif (i & EXT2_FLAGS_UNSIGNED_HASH)\n\t\t\tsbi->s_hash_unsigned = 3;\n\t\telse if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {\n#ifdef __CHAR_UNSIGNED__\n\t\t\tif (!(sb->s_flags & MS_RDONLY))\n\t\t\t\tes->s_flags |=\n\t\t\t\t\tcpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);\n\t\t\tsbi->s_hash_unsigned = 3;\n#else\n\t\t\tif (!(sb->s_flags & MS_RDONLY))\n\t\t\t\tes->s_flags |=\n\t\t\t\t\tcpu_to_le32(EXT2_FLAGS_SIGNED_HASH);\n#endif\n\t\t}\n\t}", "\t/* Handle clustersize */\n\tclustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);\n\thas_bigalloc = ext4_has_feature_bigalloc(sb);\n\tif (has_bigalloc) {\n\t\tif (clustersize < blocksize) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"cluster size (%d) smaller than \"\n\t\t\t\t \"block size (%d)\", clustersize, blocksize);\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (le32_to_cpu(es->s_log_cluster_size) >\n\t\t (EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"Invalid log cluster size: %u\",\n\t\t\t\t le32_to_cpu(es->s_log_cluster_size));\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tsbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -\n\t\t\tle32_to_cpu(es->s_log_block_size);\n\t\tsbi->s_clusters_per_group =\n\t\t\tle32_to_cpu(es->s_clusters_per_group);\n\t\tif (sbi->s_clusters_per_group > blocksize * 8) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"#clusters per group too big: %lu\",\n\t\t\t\t sbi->s_clusters_per_group);\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tif (sbi->s_blocks_per_group !=\n\t\t (sbi->s_clusters_per_group * (clustersize / blocksize))) {\n\t\t\text4_msg(sb, KERN_ERR, \"blocks per group (%lu) and \"\n\t\t\t\t \"clusters per group (%lu) inconsistent\",\n\t\t\t\t sbi->s_blocks_per_group,\n\t\t\t\t sbi->s_clusters_per_group);\n\t\t\tgoto failed_mount;\n\t\t}\n\t} else {\n\t\tif (clustersize != blocksize) {\n\t\t\text4_warning(sb, \"fragment/cluster size (%d) != \"\n\t\t\t\t \"block size (%d)\", clustersize,\n\t\t\t\t blocksize);\n\t\t\tclustersize = blocksize;\n\t\t}\n\t\tif (sbi->s_blocks_per_group > blocksize * 8) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t\t \"#blocks per group too big: %lu\",\n\t\t\t\t sbi->s_blocks_per_group);\n\t\t\tgoto failed_mount;\n\t\t}\n\t\tsbi->s_clusters_per_group = sbi->s_blocks_per_group;\n\t\tsbi->s_cluster_bits = 0;\n\t}\n\tsbi->s_cluster_ratio = clustersize / blocksize;", "\t/* Do we have standard group size of clustersize * 8 blocks ? */\n\tif (sbi->s_blocks_per_group == clustersize << 3)\n\t\tset_opt2(sb, STD_GROUP_SIZE);", "\t/*\n\t * Test whether we have more sectors than will fit in sector_t,\n\t * and whether the max offset is addressable by the page cache.\n\t */\n\terr = generic_check_addressable(sb->s_blocksize_bits,\n\t\t\t\t\text4_blocks_count(es));\n\tif (err) {\n\t\text4_msg(sb, KERN_ERR, \"filesystem\"\n\t\t\t \" too large to mount safely on this system\");\n\t\tif (sizeof(sector_t) < 8)\n\t\t\text4_msg(sb, KERN_WARNING, \"CONFIG_LBDAF not enabled\");\n\t\tgoto failed_mount;\n\t}", "\tif (EXT4_BLOCKS_PER_GROUP(sb) == 0)\n\t\tgoto cantfind_ext4;", "\t/* check blocks count against device size */\n\tblocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;\n\tif (blocks_count && ext4_blocks_count(es) > blocks_count) {\n\t\text4_msg(sb, KERN_WARNING, \"bad geometry: block count %llu \"\n\t\t \"exceeds size of device (%llu blocks)\",\n\t\t ext4_blocks_count(es), blocks_count);\n\t\tgoto failed_mount;\n\t}", "\t/*\n\t * It makes no sense for the first data block to be beyond the end\n\t * of the filesystem.\n\t */\n\tif (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) {\n\t\text4_msg(sb, KERN_WARNING, \"bad geometry: first data \"\n\t\t\t \"block %u is beyond end of filesystem (%llu)\",\n\t\t\t le32_to_cpu(es->s_first_data_block),\n\t\t\t ext4_blocks_count(es));\n\t\tgoto failed_mount;\n\t}\n\tblocks_count = (ext4_blocks_count(es) -\n\t\t\tle32_to_cpu(es->s_first_data_block) +\n\t\t\tEXT4_BLOCKS_PER_GROUP(sb) - 1);\n\tdo_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));\n\tif (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {\n\t\text4_msg(sb, KERN_WARNING, \"groups count too large: %u \"\n\t\t \"(block count %llu, first data block %u, \"\n\t\t \"blocks per group %lu)\", sbi->s_groups_count,\n\t\t ext4_blocks_count(es),\n\t\t le32_to_cpu(es->s_first_data_block),\n\t\t EXT4_BLOCKS_PER_GROUP(sb));\n\t\tgoto failed_mount;\n\t}\n\tsbi->s_groups_count = blocks_count;\n\tsbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count,\n\t\t\t(EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));\n\tdb_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /\n\t\t EXT4_DESC_PER_BLOCK(sb);", "\tif (ext4_has_feature_meta_bg(sb)) {\n\t\tif (le32_to_cpu(es->s_first_meta_bg) >= db_count) {\n\t\t\text4_msg(sb, KERN_WARNING,\n\t\t\t\t \"first meta block group too large: %u \"\n\t\t\t\t \"(group descriptor block count %u)\",\n\t\t\t\t le32_to_cpu(es->s_first_meta_bg), db_count);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}", "\tsbi->s_group_desc = ext4_kvmalloc(db_count *\n\t\t\t\t\t sizeof(struct buffer_head *),\n\t\t\t\t\t GFP_KERNEL);\n\tif (sbi->s_group_desc == NULL) {\n\t\text4_msg(sb, KERN_ERR, \"not enough memory\");\n\t\tret = -ENOMEM;\n\t\tgoto failed_mount;\n\t}", "\tbgl_lock_init(sbi->s_blockgroup_lock);", "\tfor (i = 0; i < db_count; i++) {\n\t\tblock = descriptor_loc(sb, logical_sb_block, i);\n\t\tsbi->s_group_desc[i] = sb_bread_unmovable(sb, block);\n\t\tif (!sbi->s_group_desc[i]) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"can't read group descriptor %d\", i);\n\t\t\tdb_count = i;\n\t\t\tgoto failed_mount2;\n\t\t}\n\t}\n\tif (!ext4_check_descriptors(sb, logical_sb_block, &first_not_zeroed)) {\n\t\text4_msg(sb, KERN_ERR, \"group descriptors corrupted!\");\n\t\tret = -EFSCORRUPTED;\n\t\tgoto failed_mount2;\n\t}", "\tsbi->s_gdb_count = db_count;\n\tget_random_bytes(&sbi->s_next_generation, sizeof(u32));\n\tspin_lock_init(&sbi->s_next_gen_lock);", "\tsetup_timer(&sbi->s_err_report, print_daily_error_info,\n\t\t(unsigned long) sb);", "\t/* Register extent status tree shrinker */\n\tif (ext4_es_register_shrinker(sbi))\n\t\tgoto failed_mount3;", "\tsbi->s_stripe = ext4_get_stripe_size(sbi);\n\tsbi->s_extent_max_zeroout_kb = 32;", "\t/*\n\t * set up enough so that it can read an inode\n\t */\n\tsb->s_op = &ext4_sops;\n\tsb->s_export_op = &ext4_export_ops;\n\tsb->s_xattr = ext4_xattr_handlers;\n\tsb->s_cop = &ext4_cryptops;\n#ifdef CONFIG_QUOTA\n\tsb->dq_op = &ext4_quota_operations;\n\tif (ext4_has_feature_quota(sb))\n\t\tsb->s_qcop = &dquot_quotactl_sysfile_ops;\n\telse\n\t\tsb->s_qcop = &ext4_qctl_operations;\n\tsb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;\n#endif\n\tmemcpy(sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));", "\tINIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */\n\tmutex_init(&sbi->s_orphan_lock);", "\tsb->s_root = NULL;", "\tneeds_recovery = (es->s_last_orphan != 0 ||\n\t\t\t ext4_has_feature_journal_needs_recovery(sb));", "\tif (ext4_has_feature_mmp(sb) && !(sb->s_flags & MS_RDONLY))\n\t\tif (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))\n\t\t\tgoto failed_mount3a;", "\t/*\n\t * The first inode we look at is the journal inode. Don't try\n\t * root first: it may be modified in the journal!\n\t */\n\tif (!test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) {\n\t\tif (ext4_load_journal(sb, es, journal_devnum))\n\t\t\tgoto failed_mount3a;\n\t} else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&\n\t\t ext4_has_feature_journal_needs_recovery(sb)) {\n\t\text4_msg(sb, KERN_ERR, \"required journal recovery \"\n\t\t \"suppressed and not mounted read-only\");\n\t\tgoto failed_mount_wq;\n\t} else {\n\t\t/* Nojournal mode, all journal mount options are illegal */\n\t\tif (test_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"journal_checksum, fs mounted w/o journal\");\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\t\tif (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"journal_async_commit, fs mounted w/o journal\");\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\t\tif (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"commit=%lu, fs mounted w/o journal\",\n\t\t\t\t sbi->s_commit_interval / HZ);\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\t\tif (EXT4_MOUNT_DATA_FLAGS &\n\t\t (sbi->s_mount_opt ^ sbi->s_def_mount_opt)) {\n\t\t\text4_msg(sb, KERN_ERR, \"can't mount with \"\n\t\t\t\t \"data=, fs mounted w/o journal\");\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\t\tsbi->s_def_mount_opt &= EXT4_MOUNT_JOURNAL_CHECKSUM;\n\t\tclear_opt(sb, JOURNAL_CHECKSUM);\n\t\tclear_opt(sb, DATA_FLAGS);\n\t\tsbi->s_journal = NULL;\n\t\tneeds_recovery = 0;\n\t\tgoto no_journal;\n\t}", "\tif (ext4_has_feature_64bit(sb) &&\n\t !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,\n\t\t\t\t JBD2_FEATURE_INCOMPAT_64BIT)) {\n\t\text4_msg(sb, KERN_ERR, \"Failed to set 64-bit journal feature\");\n\t\tgoto failed_mount_wq;\n\t}", "\tif (!set_journal_csum_feature_set(sb)) {\n\t\text4_msg(sb, KERN_ERR, \"Failed to set journal checksum \"\n\t\t\t \"feature set\");\n\t\tgoto failed_mount_wq;\n\t}", "\t/* We have now updated the journal if required, so we can\n\t * validate the data journaling mode. */\n\tswitch (test_opt(sb, DATA_FLAGS)) {\n\tcase 0:\n\t\t/* No mode set, assume a default based on the journal\n\t\t * capabilities: ORDERED_DATA if the journal can\n\t\t * cope, else JOURNAL_DATA\n\t\t */\n\t\tif (jbd2_journal_check_available_features\n\t\t (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE))\n\t\t\tset_opt(sb, ORDERED_DATA);\n\t\telse\n\t\t\tset_opt(sb, JOURNAL_DATA);\n\t\tbreak;", "\tcase EXT4_MOUNT_ORDERED_DATA:\n\tcase EXT4_MOUNT_WRITEBACK_DATA:\n\t\tif (!jbd2_journal_check_available_features\n\t\t (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {\n\t\t\text4_msg(sb, KERN_ERR, \"Journal does not support \"\n\t\t\t \"requested data journaling mode\");\n\t\t\tgoto failed_mount_wq;\n\t\t}\n\tdefault:\n\t\tbreak;\n\t}\n\tset_task_ioprio(sbi->s_journal->j_task, journal_ioprio);", "\tsbi->s_journal->j_commit_callback = ext4_journal_commit_callback;", "no_journal:\n\tsbi->s_mb_cache = ext4_xattr_create_cache();\n\tif (!sbi->s_mb_cache) {\n\t\text4_msg(sb, KERN_ERR, \"Failed to create an mb_cache\");\n\t\tgoto failed_mount_wq;\n\t}", "\tif ((DUMMY_ENCRYPTION_ENABLED(sbi) || ext4_has_feature_encrypt(sb)) &&\n\t (blocksize != PAGE_SIZE)) {\n\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"Unsupported blocksize for fs encryption\");\n\t\tgoto failed_mount_wq;\n\t}", "\tif (DUMMY_ENCRYPTION_ENABLED(sbi) && !(sb->s_flags & MS_RDONLY) &&\n\t !ext4_has_feature_encrypt(sb)) {\n\t\text4_set_feature_encrypt(sb);\n\t\text4_commit_super(sb, 1);\n\t}", "\t/*\n\t * Get the # of file system overhead blocks from the\n\t * superblock if present.\n\t */\n\tif (es->s_overhead_clusters)\n\t\tsbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);\n\telse {\n\t\terr = ext4_calculate_overhead(sb);\n\t\tif (err)\n\t\t\tgoto failed_mount_wq;\n\t}", "\t/*\n\t * The maximum number of concurrent works can be high and\n\t * concurrency isn't really necessary. Limit it to 1.\n\t */\n\tEXT4_SB(sb)->rsv_conversion_wq =\n\t\talloc_workqueue(\"ext4-rsv-conversion\", WQ_MEM_RECLAIM | WQ_UNBOUND, 1);\n\tif (!EXT4_SB(sb)->rsv_conversion_wq) {\n\t\tprintk(KERN_ERR \"EXT4-fs: failed to create workqueue\\n\");\n\t\tret = -ENOMEM;\n\t\tgoto failed_mount4;\n\t}", "\t/*\n\t * The jbd2_journal_load will have done any necessary log recovery,\n\t * so we can safely mount the rest of the filesystem now.\n\t */", "\troot = ext4_iget(sb, EXT4_ROOT_INO);\n\tif (IS_ERR(root)) {\n\t\text4_msg(sb, KERN_ERR, \"get root inode failed\");\n\t\tret = PTR_ERR(root);\n\t\troot = NULL;\n\t\tgoto failed_mount4;\n\t}\n\tif (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {\n\t\text4_msg(sb, KERN_ERR, \"corrupt root inode, run e2fsck\");\n\t\tiput(root);\n\t\tgoto failed_mount4;\n\t}\n\tsb->s_root = d_make_root(root);\n\tif (!sb->s_root) {\n\t\text4_msg(sb, KERN_ERR, \"get root dentry failed\");\n\t\tret = -ENOMEM;\n\t\tgoto failed_mount4;\n\t}", "\tif (ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY))\n\t\tsb->s_flags |= MS_RDONLY;", "\t/* determine the minimum size of new large inodes, if present */\n\tif (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {\n\t\tsbi->s_want_extra_isize = sizeof(struct ext4_inode) -\n\t\t\t\t\t\t EXT4_GOOD_OLD_INODE_SIZE;\n\t\tif (ext4_has_feature_extra_isize(sb)) {\n\t\t\tif (sbi->s_want_extra_isize <\n\t\t\t le16_to_cpu(es->s_want_extra_isize))\n\t\t\t\tsbi->s_want_extra_isize =\n\t\t\t\t\tle16_to_cpu(es->s_want_extra_isize);\n\t\t\tif (sbi->s_want_extra_isize <\n\t\t\t le16_to_cpu(es->s_min_extra_isize))\n\t\t\t\tsbi->s_want_extra_isize =\n\t\t\t\t\tle16_to_cpu(es->s_min_extra_isize);\n\t\t}\n\t}\n\t/* Check if enough inode space is available */\n\tif (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >\n\t\t\t\t\t\t\tsbi->s_inode_size) {\n\t\tsbi->s_want_extra_isize = sizeof(struct ext4_inode) -\n\t\t\t\t\t\t EXT4_GOOD_OLD_INODE_SIZE;\n\t\text4_msg(sb, KERN_INFO, \"required extra inode space not\"\n\t\t\t \"available\");\n\t}", "\text4_set_resv_clusters(sb);", "\terr = ext4_setup_system_zone(sb);\n\tif (err) {\n\t\text4_msg(sb, KERN_ERR, \"failed to initialize system \"\n\t\t\t \"zone (%d)\", err);\n\t\tgoto failed_mount4a;\n\t}", "\text4_ext_init(sb);\n\terr = ext4_mb_init(sb);\n\tif (err) {\n\t\text4_msg(sb, KERN_ERR, \"failed to initialize mballoc (%d)\",\n\t\t\t err);\n\t\tgoto failed_mount5;\n\t}", "\tblock = ext4_count_free_clusters(sb);\n\text4_free_blocks_count_set(sbi->s_es, \n\t\t\t\t EXT4_C2B(sbi, block));\n\terr = percpu_counter_init(&sbi->s_freeclusters_counter, block,\n\t\t\t\t GFP_KERNEL);\n\tif (!err) {\n\t\tunsigned long freei = ext4_count_free_inodes(sb);\n\t\tsbi->s_es->s_free_inodes_count = cpu_to_le32(freei);\n\t\terr = percpu_counter_init(&sbi->s_freeinodes_counter, freei,\n\t\t\t\t\t GFP_KERNEL);\n\t}\n\tif (!err)\n\t\terr = percpu_counter_init(&sbi->s_dirs_counter,\n\t\t\t\t\t ext4_count_dirs(sb), GFP_KERNEL);\n\tif (!err)\n\t\terr = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0,\n\t\t\t\t\t GFP_KERNEL);\n\tif (!err)\n\t\terr = percpu_init_rwsem(&sbi->s_journal_flag_rwsem);", "\tif (err) {\n\t\text4_msg(sb, KERN_ERR, \"insufficient memory\");\n\t\tgoto failed_mount6;\n\t}", "\tif (ext4_has_feature_flex_bg(sb))\n\t\tif (!ext4_fill_flex_info(sb)) {\n\t\t\text4_msg(sb, KERN_ERR,\n\t\t\t \"unable to initialize \"\n\t\t\t \"flex_bg meta info!\");\n\t\t\tgoto failed_mount6;\n\t\t}", "\terr = ext4_register_li_request(sb, first_not_zeroed);\n\tif (err)\n\t\tgoto failed_mount6;", "\terr = ext4_register_sysfs(sb);\n\tif (err)\n\t\tgoto failed_mount7;", "#ifdef CONFIG_QUOTA\n\t/* Enable quota usage during mount. */\n\tif (ext4_has_feature_quota(sb) && !(sb->s_flags & MS_RDONLY)) {\n\t\terr = ext4_enable_quotas(sb);\n\t\tif (err)\n\t\t\tgoto failed_mount8;\n\t}\n#endif /* CONFIG_QUOTA */", "\tEXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;\n\text4_orphan_cleanup(sb, es);\n\tEXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;\n\tif (needs_recovery) {\n\t\text4_msg(sb, KERN_INFO, \"recovery complete\");\n\t\text4_mark_recovery_complete(sb, es);\n\t}\n\tif (EXT4_SB(sb)->s_journal) {\n\t\tif (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)\n\t\t\tdescr = \" journalled data mode\";\n\t\telse if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)\n\t\t\tdescr = \" ordered data mode\";\n\t\telse\n\t\t\tdescr = \" writeback data mode\";\n\t} else\n\t\tdescr = \"out journal\";", "\tif (test_opt(sb, DISCARD)) {\n\t\tstruct request_queue *q = bdev_get_queue(sb->s_bdev);\n\t\tif (!blk_queue_discard(q))\n\t\t\text4_msg(sb, KERN_WARNING,\n\t\t\t\t \"mounting with \\\"discard\\\" option, but \"\n\t\t\t\t \"the device does not support discard\");\n\t}", "\tif (___ratelimit(&ext4_mount_msg_ratelimit, \"EXT4-fs mount\"))\n\t\text4_msg(sb, KERN_INFO, \"mounted filesystem with%s. \"\n\t\t\t \"Opts: %.*s%s%s\", descr,\n\t\t\t (int) sizeof(sbi->s_es->s_mount_opts),\n\t\t\t sbi->s_es->s_mount_opts,\n\t\t\t *sbi->s_es->s_mount_opts ? \"; \" : \"\", orig_data);", "\tif (es->s_error_count)\n\t\tmod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */", "\t/* Enable message ratelimiting. Default is 10 messages per 5 secs. */\n\tratelimit_state_init(&sbi->s_err_ratelimit_state, 5 * HZ, 10);\n\tratelimit_state_init(&sbi->s_warning_ratelimit_state, 5 * HZ, 10);\n\tratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10);", "\tkfree(orig_data);\n#ifdef CONFIG_EXT4_FS_ENCRYPTION\n\tmemcpy(sbi->key_prefix, EXT4_KEY_DESC_PREFIX,\n\t\t\t\tEXT4_KEY_DESC_PREFIX_SIZE);\n\tsbi->key_prefix_size = EXT4_KEY_DESC_PREFIX_SIZE;\n#endif\n\treturn 0;", "cantfind_ext4:\n\tif (!silent)\n\t\text4_msg(sb, KERN_ERR, \"VFS: Can't find ext4 filesystem\");\n\tgoto failed_mount;", "#ifdef CONFIG_QUOTA\nfailed_mount8:\n\text4_unregister_sysfs(sb);\n#endif\nfailed_mount7:\n\text4_unregister_li_request(sb);\nfailed_mount6:\n\text4_mb_release(sb);\n\tif (sbi->s_flex_groups)\n\t\tkvfree(sbi->s_flex_groups);\n\tpercpu_counter_destroy(&sbi->s_freeclusters_counter);\n\tpercpu_counter_destroy(&sbi->s_freeinodes_counter);\n\tpercpu_counter_destroy(&sbi->s_dirs_counter);\n\tpercpu_counter_destroy(&sbi->s_dirtyclusters_counter);\nfailed_mount5:\n\text4_ext_release(sb);\n\text4_release_system_zone(sb);\nfailed_mount4a:\n\tdput(sb->s_root);\n\tsb->s_root = NULL;\nfailed_mount4:\n\text4_msg(sb, KERN_ERR, \"mount failed\");\n\tif (EXT4_SB(sb)->rsv_conversion_wq)\n\t\tdestroy_workqueue(EXT4_SB(sb)->rsv_conversion_wq);\nfailed_mount_wq:\n\tif (sbi->s_mb_cache) {\n\t\text4_xattr_destroy_cache(sbi->s_mb_cache);\n\t\tsbi->s_mb_cache = NULL;\n\t}\n\tif (sbi->s_journal) {\n\t\tjbd2_journal_destroy(sbi->s_journal);\n\t\tsbi->s_journal = NULL;\n\t}\nfailed_mount3a:\n\text4_es_unregister_shrinker(sbi);\nfailed_mount3:\n\tdel_timer_sync(&sbi->s_err_report);\n\tif (sbi->s_mmp_tsk)\n\t\tkthread_stop(sbi->s_mmp_tsk);\nfailed_mount2:\n\tfor (i = 0; i < db_count; i++)\n\t\tbrelse(sbi->s_group_desc[i]);\n\tkvfree(sbi->s_group_desc);\nfailed_mount:\n\tif (sbi->s_chksum_driver)\n\t\tcrypto_free_shash(sbi->s_chksum_driver);\n#ifdef CONFIG_QUOTA\n\tfor (i = 0; i < EXT4_MAXQUOTAS; i++)\n\t\tkfree(sbi->s_qf_names[i]);\n#endif\n\text4_blkdev_remove(sbi);\n\tbrelse(bh);\nout_fail:\n\tsb->s_fs_info = NULL;\n\tkfree(sbi->s_blockgroup_lock);\nout_free_base:\n\tkfree(sbi);\n\tkfree(orig_data);\n\treturn err ? err : ret;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 16999, "char_start": 16712, "chars": "if (ext4_has_feature_meta_bg(sb)) {\n\t\tif (le32_to_cpu(es->s_first_meta_bg) >= db_count) {\n\t\t\text4_msg(sb, KERN_WARNING,\n\t\t\t\t \"first meta block group too large: %u \"\n\t\t\t\t \"(group descriptor block count %u)\",\n\t\t\t\t le32_to_cpu(es->s_first_meta_bg), db_count);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\t" } ], "deleted": [] }, "commit_link": "github.com/torvalds/linux/commit/3a4b77cd47bb837b8557595ec7425f281f2ca1fe", "file_name": "fs/ext4/super.c", "func_name": "ext4_fill_super", "line_changes": { "added": [ { "char_end": 16748, "char_start": 16711, "line": "\tif (ext4_has_feature_meta_bg(sb)) {\n", "line_no": 522 }, { "char_end": 16802, "char_start": 16748, "line": "\t\tif (le32_to_cpu(es->s_first_meta_bg) >= db_count) {\n", "line_no": 523 }, { "char_end": 16832, "char_start": 16802, "line": "\t\t\text4_msg(sb, KERN_WARNING,\n", "line_no": 524 }, { "char_end": 16877, "char_start": 16832, "line": "\t\t\t\t \"first meta block group too large: %u \"\n", "line_no": 525 }, { "char_end": 16919, "char_start": 16877, "line": "\t\t\t\t \"(group descriptor block count %u)\",\n", "line_no": 526 }, { "char_end": 16969, "char_start": 16919, "line": "\t\t\t\t le32_to_cpu(es->s_first_meta_bg), db_count);\n", "line_no": 527 }, { "char_end": 16991, "char_start": 16969, "line": "\t\t\tgoto failed_mount;\n", "line_no": 528 }, { "char_end": 16995, "char_start": 16991, "line": "\t\t}\n", "line_no": 529 }, { "char_end": 16998, "char_start": 16995, "line": "\t}\n", "line_no": 530 } ], "deleted": [] }, "vul_type": "cwe-125" }
459
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int mxf_parse_structural_metadata(MXFContext *mxf)\n{\n MXFPackage *material_package = NULL;\n int i, j, k, ret;", " av_log(mxf->fc, AV_LOG_TRACE, \"metadata sets count %d\\n\", mxf->metadata_sets_count);\n /* TODO: handle multiple material packages (OP3x) */\n for (i = 0; i < mxf->packages_count; i++) {\n material_package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[i], MaterialPackage);\n if (material_package) break;\n }\n if (!material_package) {\n av_log(mxf->fc, AV_LOG_ERROR, \"no material package found\\n\");\n return AVERROR_INVALIDDATA;\n }", " mxf_add_umid_metadata(&mxf->fc->metadata, \"material_package_umid\", material_package);\n if (material_package->name && material_package->name[0])\n av_dict_set(&mxf->fc->metadata, \"material_package_name\", material_package->name, 0);\n mxf_parse_package_comments(mxf, &mxf->fc->metadata, material_package);", " for (i = 0; i < material_package->tracks_count; i++) {\n MXFPackage *source_package = NULL;\n MXFTrack *material_track = NULL;\n MXFTrack *source_track = NULL;\n MXFTrack *temp_track = NULL;\n MXFDescriptor *descriptor = NULL;\n MXFStructuralComponent *component = NULL;\n MXFTimecodeComponent *mxf_tc = NULL;\n UID *essence_container_ul = NULL;\n const MXFCodecUL *codec_ul = NULL;\n const MXFCodecUL *container_ul = NULL;\n const MXFCodecUL *pix_fmt_ul = NULL;\n AVStream *st;\n AVTimecode tc;\n int flags;", " if (!(material_track = mxf_resolve_strong_ref(mxf, &material_package->tracks_refs[i], Track))) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not resolve material track strong ref\\n\");\n continue;\n }", " if ((component = mxf_resolve_strong_ref(mxf, &material_track->sequence_ref, TimecodeComponent))) {\n mxf_tc = (MXFTimecodeComponent*)component;\n flags = mxf_tc->drop_frame == 1 ? AV_TIMECODE_FLAG_DROPFRAME : 0;\n if (av_timecode_init(&tc, mxf_tc->rate, flags, mxf_tc->start_frame, mxf->fc) == 0) {\n mxf_add_timecode_metadata(&mxf->fc->metadata, \"timecode\", &tc);\n }\n }", " if (!(material_track->sequence = mxf_resolve_strong_ref(mxf, &material_track->sequence_ref, Sequence))) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not resolve material track sequence strong ref\\n\");\n continue;\n }", " for (j = 0; j < material_track->sequence->structural_components_count; j++) {\n component = mxf_resolve_strong_ref(mxf, &material_track->sequence->structural_components_refs[j], TimecodeComponent);\n if (!component)\n continue;", " mxf_tc = (MXFTimecodeComponent*)component;\n flags = mxf_tc->drop_frame == 1 ? AV_TIMECODE_FLAG_DROPFRAME : 0;\n if (av_timecode_init(&tc, mxf_tc->rate, flags, mxf_tc->start_frame, mxf->fc) == 0) {\n mxf_add_timecode_metadata(&mxf->fc->metadata, \"timecode\", &tc);\n break;\n }\n }", " /* TODO: handle multiple source clips, only finds first valid source clip */\n if(material_track->sequence->structural_components_count > 1)\n av_log(mxf->fc, AV_LOG_WARNING, \"material track %d: has %d components\\n\",\n material_track->track_id, material_track->sequence->structural_components_count);", " for (j = 0; j < material_track->sequence->structural_components_count; j++) {\n component = mxf_resolve_sourceclip(mxf, &material_track->sequence->structural_components_refs[j]);\n if (!component)\n continue;", " source_package = mxf_resolve_source_package(mxf, component->source_package_ul, component->source_package_uid);\n if (!source_package) {\n av_log(mxf->fc, AV_LOG_TRACE, \"material track %d: no corresponding source package found\\n\", material_track->track_id);\n continue;\n }\n for (k = 0; k < source_package->tracks_count; k++) {\n if (!(temp_track = mxf_resolve_strong_ref(mxf, &source_package->tracks_refs[k], Track))) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not resolve source track strong ref\\n\");\n ret = AVERROR_INVALIDDATA;\n goto fail_and_free;\n }\n if (temp_track->track_id == component->source_track_id) {\n source_track = temp_track;\n break;\n }\n }\n if (!source_track) {\n av_log(mxf->fc, AV_LOG_ERROR, \"material track %d: no corresponding source track found\\n\", material_track->track_id);\n break;\n }", " for (k = 0; k < mxf->essence_container_data_count; k++) {\n MXFEssenceContainerData *essence_data;", " if (!(essence_data = mxf_resolve_strong_ref(mxf, &mxf->essence_container_data_refs[k], EssenceContainerData))) {", " av_log(mxf, AV_LOG_TRACE, \"could not resolve essence container data strong ref\\n\");", " continue;\n }\n if (!memcmp(component->source_package_ul, essence_data->package_ul, sizeof(UID)) && !memcmp(component->source_package_uid, essence_data->package_uid, sizeof(UID))) {\n source_track->body_sid = essence_data->body_sid;\n source_track->index_sid = essence_data->index_sid;\n break;\n }\n }", " if(source_track && component)\n break;\n }\n if (!source_track || !component || !source_package) {\n if((ret = mxf_add_metadata_stream(mxf, material_track)))\n goto fail_and_free;\n continue;\n }", " if (!(source_track->sequence = mxf_resolve_strong_ref(mxf, &source_track->sequence_ref, Sequence))) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not resolve source track sequence strong ref\\n\");\n ret = AVERROR_INVALIDDATA;\n goto fail_and_free;\n }", " /* 0001GL00.MXF.A1.mxf_opatom.mxf has the same SourcePackageID as 0001GL.MXF.V1.mxf_opatom.mxf\n * This would result in both files appearing to have two streams. Work around this by sanity checking DataDefinition */\n if (memcmp(material_track->sequence->data_definition_ul, source_track->sequence->data_definition_ul, 16)) {\n av_log(mxf->fc, AV_LOG_ERROR, \"material track %d: DataDefinition mismatch\\n\", material_track->track_id);\n continue;\n }", " st = avformat_new_stream(mxf->fc, NULL);\n if (!st) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not allocate stream\\n\");\n ret = AVERROR(ENOMEM);\n goto fail_and_free;\n }\n st->id = material_track->track_id;\n st->priv_data = source_track;", " source_package->descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor_ref, AnyType);\n descriptor = mxf_resolve_multidescriptor(mxf, source_package->descriptor, source_track->track_id);", " /* A SourceClip from a EssenceGroup may only be a single frame of essence data. The clips duration is then how many\n * frames its suppose to repeat for. Descriptor->duration, if present, contains the real duration of the essence data */\n if (descriptor && descriptor->duration != AV_NOPTS_VALUE)\n source_track->original_duration = st->duration = FFMIN(descriptor->duration, component->duration);\n else\n source_track->original_duration = st->duration = component->duration;", " if (st->duration == -1)\n st->duration = AV_NOPTS_VALUE;\n st->start_time = component->start_position;\n if (material_track->edit_rate.num <= 0 ||\n material_track->edit_rate.den <= 0) {\n av_log(mxf->fc, AV_LOG_WARNING,\n \"Invalid edit rate (%d/%d) found on stream #%d, \"\n \"defaulting to 25/1\\n\",\n material_track->edit_rate.num,\n material_track->edit_rate.den, st->index);\n material_track->edit_rate = (AVRational){25, 1};\n }\n avpriv_set_pts_info(st, 64, material_track->edit_rate.den, material_track->edit_rate.num);", " /* ensure SourceTrack EditRate == MaterialTrack EditRate since only\n * the former is accessible via st->priv_data */\n source_track->edit_rate = material_track->edit_rate;", " PRINT_KEY(mxf->fc, \"data definition ul\", source_track->sequence->data_definition_ul);\n codec_ul = mxf_get_codec_ul(ff_mxf_data_definition_uls, &source_track->sequence->data_definition_ul);\n st->codecpar->codec_type = codec_ul->id;", " if (!descriptor) {\n av_log(mxf->fc, AV_LOG_INFO, \"source track %d: stream %d, no descriptor found\\n\", source_track->track_id, st->index);\n continue;\n }\n PRINT_KEY(mxf->fc, \"essence codec ul\", descriptor->essence_codec_ul);\n PRINT_KEY(mxf->fc, \"essence container ul\", descriptor->essence_container_ul);\n essence_container_ul = &descriptor->essence_container_ul;\n source_track->wrapping = (mxf->op == OPAtom) ? ClipWrapped : mxf_get_wrapping_kind(essence_container_ul);\n if (source_track->wrapping == UnknownWrapped)\n av_log(mxf->fc, AV_LOG_INFO, \"wrapping of stream %d is unknown\\n\", st->index);\n /* HACK: replacing the original key with mxf_encrypted_essence_container\n * is not allowed according to s429-6, try to find correct information anyway */\n if (IS_KLV_KEY(essence_container_ul, mxf_encrypted_essence_container)) {\n av_log(mxf->fc, AV_LOG_INFO, \"broken encrypted mxf file\\n\");\n for (k = 0; k < mxf->metadata_sets_count; k++) {\n MXFMetadataSet *metadata = mxf->metadata_sets[k];\n if (metadata->type == CryptoContext) {\n essence_container_ul = &((MXFCryptoContext *)metadata)->source_container_ul;\n break;\n }\n }\n }", " /* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */\n codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->essence_codec_ul);\n st->codecpar->codec_id = (enum AVCodecID)codec_ul->id;\n if (st->codecpar->codec_id == AV_CODEC_ID_NONE) {\n codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->codec_ul);\n st->codecpar->codec_id = (enum AVCodecID)codec_ul->id;\n }", " av_log(mxf->fc, AV_LOG_VERBOSE, \"%s: Universal Label: \",\n avcodec_get_name(st->codecpar->codec_id));\n for (k = 0; k < 16; k++) {\n av_log(mxf->fc, AV_LOG_VERBOSE, \"%.2x\",\n descriptor->essence_codec_ul[k]);\n if (!(k+1 & 19) || k == 5)\n av_log(mxf->fc, AV_LOG_VERBOSE, \".\");\n }\n av_log(mxf->fc, AV_LOG_VERBOSE, \"\\n\");", " mxf_add_umid_metadata(&st->metadata, \"file_package_umid\", source_package);\n if (source_package->name && source_package->name[0])\n av_dict_set(&st->metadata, \"file_package_name\", source_package->name, 0);\n if (material_track->name && material_track->name[0])\n av_dict_set(&st->metadata, \"track_name\", material_track->name, 0);", " mxf_parse_physical_source_package(mxf, source_track, st);", " if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {\n source_track->intra_only = mxf_is_intra_only(descriptor);\n container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, essence_container_ul);\n if (st->codecpar->codec_id == AV_CODEC_ID_NONE)\n st->codecpar->codec_id = container_ul->id;\n st->codecpar->width = descriptor->width;\n st->codecpar->height = descriptor->height; /* Field height, not frame height */\n switch (descriptor->frame_layout) {\n case FullFrame:\n st->codecpar->field_order = AV_FIELD_PROGRESSIVE;\n break;\n case OneField:\n /* Every other line is stored and needs to be duplicated. */\n av_log(mxf->fc, AV_LOG_INFO, \"OneField frame layout isn't currently supported\\n\");\n break; /* The correct thing to do here is fall through, but by breaking we might be\n able to decode some streams at half the vertical resolution, rather than not al all.\n It's also for compatibility with the old behavior. */\n case MixedFields:\n break;\n case SegmentedFrame:\n st->codecpar->field_order = AV_FIELD_PROGRESSIVE;\n case SeparateFields:\n av_log(mxf->fc, AV_LOG_DEBUG, \"video_line_map: (%d, %d), field_dominance: %d\\n\",\n descriptor->video_line_map[0], descriptor->video_line_map[1],\n descriptor->field_dominance);\n if ((descriptor->video_line_map[0] > 0) && (descriptor->video_line_map[1] > 0)) {\n /* Detect coded field order from VideoLineMap:\n * (even, even) => bottom field coded first\n * (even, odd) => top field coded first\n * (odd, even) => top field coded first\n * (odd, odd) => bottom field coded first\n */\n if ((descriptor->video_line_map[0] + descriptor->video_line_map[1]) % 2) {\n switch (descriptor->field_dominance) {\n case MXF_FIELD_DOMINANCE_DEFAULT:\n case MXF_FIELD_DOMINANCE_FF:\n st->codecpar->field_order = AV_FIELD_TT;\n break;\n case MXF_FIELD_DOMINANCE_FL:\n st->codecpar->field_order = AV_FIELD_TB;\n break;\n default:\n avpriv_request_sample(mxf->fc,\n \"Field dominance %d support\",\n descriptor->field_dominance);\n }\n } else {\n switch (descriptor->field_dominance) {\n case MXF_FIELD_DOMINANCE_DEFAULT:\n case MXF_FIELD_DOMINANCE_FF:\n st->codecpar->field_order = AV_FIELD_BB;\n break;\n case MXF_FIELD_DOMINANCE_FL:\n st->codecpar->field_order = AV_FIELD_BT;\n break;\n default:\n avpriv_request_sample(mxf->fc,\n \"Field dominance %d support\",\n descriptor->field_dominance);\n }\n }\n }\n /* Turn field height into frame height. */\n st->codecpar->height *= 2;\n break;\n default:\n av_log(mxf->fc, AV_LOG_INFO, \"Unknown frame layout type: %d\\n\", descriptor->frame_layout);\n }\n if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) {\n st->codecpar->format = descriptor->pix_fmt;\n if (st->codecpar->format == AV_PIX_FMT_NONE) {\n pix_fmt_ul = mxf_get_codec_ul(ff_mxf_pixel_format_uls,\n &descriptor->essence_codec_ul);\n st->codecpar->format = (enum AVPixelFormat)pix_fmt_ul->id;\n if (st->codecpar->format== AV_PIX_FMT_NONE) {\n st->codecpar->codec_tag = mxf_get_codec_ul(ff_mxf_codec_tag_uls,\n &descriptor->essence_codec_ul)->id;\n if (!st->codecpar->codec_tag) {\n /* support files created before RP224v10 by defaulting to UYVY422\n if subsampling is 4:2:2 and component depth is 8-bit */\n if (descriptor->horiz_subsampling == 2 &&\n descriptor->vert_subsampling == 1 &&\n descriptor->component_depth == 8) {\n st->codecpar->format = AV_PIX_FMT_UYVY422;\n }\n }\n }\n }\n }\n st->need_parsing = AVSTREAM_PARSE_HEADERS;\n if (material_track->sequence->origin) {\n av_dict_set_int(&st->metadata, \"material_track_origin\", material_track->sequence->origin, 0);\n }\n if (source_track->sequence->origin) {\n av_dict_set_int(&st->metadata, \"source_track_origin\", source_track->sequence->origin, 0);\n }\n if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den)\n st->display_aspect_ratio = descriptor->aspect_ratio;\n } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {\n container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul);\n /* Only overwrite existing codec ID if it is unset or A-law, which is the default according to SMPTE RP 224. */\n if (st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW && (enum AVCodecID)container_ul->id != AV_CODEC_ID_NONE))\n st->codecpar->codec_id = (enum AVCodecID)container_ul->id;\n st->codecpar->channels = descriptor->channels;\n st->codecpar->bits_per_coded_sample = descriptor->bits_per_sample;", " if (descriptor->sample_rate.den > 0) {\n st->codecpar->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;\n avpriv_set_pts_info(st, 64, descriptor->sample_rate.den, descriptor->sample_rate.num);\n } else {\n av_log(mxf->fc, AV_LOG_WARNING, \"invalid sample rate (%d/%d) \"\n \"found for stream #%d, time base forced to 1/48000\\n\",\n descriptor->sample_rate.num, descriptor->sample_rate.den,\n st->index);\n avpriv_set_pts_info(st, 64, 1, 48000);\n }", " /* if duration is set, rescale it from EditRate to SampleRate */\n if (st->duration != AV_NOPTS_VALUE)\n st->duration = av_rescale_q(st->duration,\n av_inv_q(material_track->edit_rate),\n st->time_base);", " /* TODO: implement AV_CODEC_ID_RAWAUDIO */\n if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) {\n if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24)\n st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;\n else if (descriptor->bits_per_sample == 32)\n st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;\n } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) {\n if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24)\n st->codecpar->codec_id = AV_CODEC_ID_PCM_S24BE;\n else if (descriptor->bits_per_sample == 32)\n st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE;\n } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) {\n st->need_parsing = AVSTREAM_PARSE_FULL;\n }\n } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {\n enum AVMediaType type;\n container_ul = mxf_get_codec_ul(mxf_data_essence_container_uls, essence_container_ul);\n if (st->codecpar->codec_id == AV_CODEC_ID_NONE)\n st->codecpar->codec_id = container_ul->id;\n type = avcodec_get_type(st->codecpar->codec_id);\n if (type == AVMEDIA_TYPE_SUBTITLE)\n st->codecpar->codec_type = type;\n if (container_ul->desc)\n av_dict_set(&st->metadata, \"data_type\", container_ul->desc, 0);\n }\n if (descriptor->extradata) {\n if (!ff_alloc_extradata(st->codecpar, descriptor->extradata_size)) {\n memcpy(st->codecpar->extradata, descriptor->extradata, descriptor->extradata_size);\n }\n } else if (st->codecpar->codec_id == AV_CODEC_ID_H264) {\n int coded_width = mxf_get_codec_ul(mxf_intra_only_picture_coded_width,\n &descriptor->essence_codec_ul)->id;\n if (coded_width)\n st->codecpar->width = coded_width;\n ret = ff_generate_avci_extradata(st);\n if (ret < 0)\n return ret;\n }\n if (st->codecpar->codec_type != AVMEDIA_TYPE_DATA && source_track->wrapping != FrameWrapped) {\n /* TODO: decode timestamps */\n st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;\n }\n }", " ret = 0;\nfail_and_free:\n return ret;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 5047, "char_start": 5043, "chars": "->fc" } ], "deleted": [] }, "commit_link": "github.com/FFmpeg/FFmpeg/commit/bab0716c7f4793ec42e05a5aa7e80d82a0dd4e75", "file_name": "libavformat/mxfdec.c", "func_name": "mxf_parse_structural_metadata", "line_changes": { "added": [ { "char_end": 5121, "char_start": 5013, "line": " av_log(mxf->fc, AV_LOG_TRACE, \"could not resolve essence container data strong ref\\n\");\n", "line_no": 104 } ], "deleted": [ { "char_end": 5117, "char_start": 5013, "line": " av_log(mxf, AV_LOG_TRACE, \"could not resolve essence container data strong ref\\n\");\n", "line_no": 104 } ] }, "vul_type": "cwe-125" }
460
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int mxf_parse_structural_metadata(MXFContext *mxf)\n{\n MXFPackage *material_package = NULL;\n int i, j, k, ret;", " av_log(mxf->fc, AV_LOG_TRACE, \"metadata sets count %d\\n\", mxf->metadata_sets_count);\n /* TODO: handle multiple material packages (OP3x) */\n for (i = 0; i < mxf->packages_count; i++) {\n material_package = mxf_resolve_strong_ref(mxf, &mxf->packages_refs[i], MaterialPackage);\n if (material_package) break;\n }\n if (!material_package) {\n av_log(mxf->fc, AV_LOG_ERROR, \"no material package found\\n\");\n return AVERROR_INVALIDDATA;\n }", " mxf_add_umid_metadata(&mxf->fc->metadata, \"material_package_umid\", material_package);\n if (material_package->name && material_package->name[0])\n av_dict_set(&mxf->fc->metadata, \"material_package_name\", material_package->name, 0);\n mxf_parse_package_comments(mxf, &mxf->fc->metadata, material_package);", " for (i = 0; i < material_package->tracks_count; i++) {\n MXFPackage *source_package = NULL;\n MXFTrack *material_track = NULL;\n MXFTrack *source_track = NULL;\n MXFTrack *temp_track = NULL;\n MXFDescriptor *descriptor = NULL;\n MXFStructuralComponent *component = NULL;\n MXFTimecodeComponent *mxf_tc = NULL;\n UID *essence_container_ul = NULL;\n const MXFCodecUL *codec_ul = NULL;\n const MXFCodecUL *container_ul = NULL;\n const MXFCodecUL *pix_fmt_ul = NULL;\n AVStream *st;\n AVTimecode tc;\n int flags;", " if (!(material_track = mxf_resolve_strong_ref(mxf, &material_package->tracks_refs[i], Track))) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not resolve material track strong ref\\n\");\n continue;\n }", " if ((component = mxf_resolve_strong_ref(mxf, &material_track->sequence_ref, TimecodeComponent))) {\n mxf_tc = (MXFTimecodeComponent*)component;\n flags = mxf_tc->drop_frame == 1 ? AV_TIMECODE_FLAG_DROPFRAME : 0;\n if (av_timecode_init(&tc, mxf_tc->rate, flags, mxf_tc->start_frame, mxf->fc) == 0) {\n mxf_add_timecode_metadata(&mxf->fc->metadata, \"timecode\", &tc);\n }\n }", " if (!(material_track->sequence = mxf_resolve_strong_ref(mxf, &material_track->sequence_ref, Sequence))) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not resolve material track sequence strong ref\\n\");\n continue;\n }", " for (j = 0; j < material_track->sequence->structural_components_count; j++) {\n component = mxf_resolve_strong_ref(mxf, &material_track->sequence->structural_components_refs[j], TimecodeComponent);\n if (!component)\n continue;", " mxf_tc = (MXFTimecodeComponent*)component;\n flags = mxf_tc->drop_frame == 1 ? AV_TIMECODE_FLAG_DROPFRAME : 0;\n if (av_timecode_init(&tc, mxf_tc->rate, flags, mxf_tc->start_frame, mxf->fc) == 0) {\n mxf_add_timecode_metadata(&mxf->fc->metadata, \"timecode\", &tc);\n break;\n }\n }", " /* TODO: handle multiple source clips, only finds first valid source clip */\n if(material_track->sequence->structural_components_count > 1)\n av_log(mxf->fc, AV_LOG_WARNING, \"material track %d: has %d components\\n\",\n material_track->track_id, material_track->sequence->structural_components_count);", " for (j = 0; j < material_track->sequence->structural_components_count; j++) {\n component = mxf_resolve_sourceclip(mxf, &material_track->sequence->structural_components_refs[j]);\n if (!component)\n continue;", " source_package = mxf_resolve_source_package(mxf, component->source_package_ul, component->source_package_uid);\n if (!source_package) {\n av_log(mxf->fc, AV_LOG_TRACE, \"material track %d: no corresponding source package found\\n\", material_track->track_id);\n continue;\n }\n for (k = 0; k < source_package->tracks_count; k++) {\n if (!(temp_track = mxf_resolve_strong_ref(mxf, &source_package->tracks_refs[k], Track))) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not resolve source track strong ref\\n\");\n ret = AVERROR_INVALIDDATA;\n goto fail_and_free;\n }\n if (temp_track->track_id == component->source_track_id) {\n source_track = temp_track;\n break;\n }\n }\n if (!source_track) {\n av_log(mxf->fc, AV_LOG_ERROR, \"material track %d: no corresponding source track found\\n\", material_track->track_id);\n break;\n }", " for (k = 0; k < mxf->essence_container_data_count; k++) {\n MXFEssenceContainerData *essence_data;", " if (!(essence_data = mxf_resolve_strong_ref(mxf, &mxf->essence_container_data_refs[k], EssenceContainerData))) {", " av_log(mxf->fc, AV_LOG_TRACE, \"could not resolve essence container data strong ref\\n\");", " continue;\n }\n if (!memcmp(component->source_package_ul, essence_data->package_ul, sizeof(UID)) && !memcmp(component->source_package_uid, essence_data->package_uid, sizeof(UID))) {\n source_track->body_sid = essence_data->body_sid;\n source_track->index_sid = essence_data->index_sid;\n break;\n }\n }", " if(source_track && component)\n break;\n }\n if (!source_track || !component || !source_package) {\n if((ret = mxf_add_metadata_stream(mxf, material_track)))\n goto fail_and_free;\n continue;\n }", " if (!(source_track->sequence = mxf_resolve_strong_ref(mxf, &source_track->sequence_ref, Sequence))) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not resolve source track sequence strong ref\\n\");\n ret = AVERROR_INVALIDDATA;\n goto fail_and_free;\n }", " /* 0001GL00.MXF.A1.mxf_opatom.mxf has the same SourcePackageID as 0001GL.MXF.V1.mxf_opatom.mxf\n * This would result in both files appearing to have two streams. Work around this by sanity checking DataDefinition */\n if (memcmp(material_track->sequence->data_definition_ul, source_track->sequence->data_definition_ul, 16)) {\n av_log(mxf->fc, AV_LOG_ERROR, \"material track %d: DataDefinition mismatch\\n\", material_track->track_id);\n continue;\n }", " st = avformat_new_stream(mxf->fc, NULL);\n if (!st) {\n av_log(mxf->fc, AV_LOG_ERROR, \"could not allocate stream\\n\");\n ret = AVERROR(ENOMEM);\n goto fail_and_free;\n }\n st->id = material_track->track_id;\n st->priv_data = source_track;", " source_package->descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor_ref, AnyType);\n descriptor = mxf_resolve_multidescriptor(mxf, source_package->descriptor, source_track->track_id);", " /* A SourceClip from a EssenceGroup may only be a single frame of essence data. The clips duration is then how many\n * frames its suppose to repeat for. Descriptor->duration, if present, contains the real duration of the essence data */\n if (descriptor && descriptor->duration != AV_NOPTS_VALUE)\n source_track->original_duration = st->duration = FFMIN(descriptor->duration, component->duration);\n else\n source_track->original_duration = st->duration = component->duration;", " if (st->duration == -1)\n st->duration = AV_NOPTS_VALUE;\n st->start_time = component->start_position;\n if (material_track->edit_rate.num <= 0 ||\n material_track->edit_rate.den <= 0) {\n av_log(mxf->fc, AV_LOG_WARNING,\n \"Invalid edit rate (%d/%d) found on stream #%d, \"\n \"defaulting to 25/1\\n\",\n material_track->edit_rate.num,\n material_track->edit_rate.den, st->index);\n material_track->edit_rate = (AVRational){25, 1};\n }\n avpriv_set_pts_info(st, 64, material_track->edit_rate.den, material_track->edit_rate.num);", " /* ensure SourceTrack EditRate == MaterialTrack EditRate since only\n * the former is accessible via st->priv_data */\n source_track->edit_rate = material_track->edit_rate;", " PRINT_KEY(mxf->fc, \"data definition ul\", source_track->sequence->data_definition_ul);\n codec_ul = mxf_get_codec_ul(ff_mxf_data_definition_uls, &source_track->sequence->data_definition_ul);\n st->codecpar->codec_type = codec_ul->id;", " if (!descriptor) {\n av_log(mxf->fc, AV_LOG_INFO, \"source track %d: stream %d, no descriptor found\\n\", source_track->track_id, st->index);\n continue;\n }\n PRINT_KEY(mxf->fc, \"essence codec ul\", descriptor->essence_codec_ul);\n PRINT_KEY(mxf->fc, \"essence container ul\", descriptor->essence_container_ul);\n essence_container_ul = &descriptor->essence_container_ul;\n source_track->wrapping = (mxf->op == OPAtom) ? ClipWrapped : mxf_get_wrapping_kind(essence_container_ul);\n if (source_track->wrapping == UnknownWrapped)\n av_log(mxf->fc, AV_LOG_INFO, \"wrapping of stream %d is unknown\\n\", st->index);\n /* HACK: replacing the original key with mxf_encrypted_essence_container\n * is not allowed according to s429-6, try to find correct information anyway */\n if (IS_KLV_KEY(essence_container_ul, mxf_encrypted_essence_container)) {\n av_log(mxf->fc, AV_LOG_INFO, \"broken encrypted mxf file\\n\");\n for (k = 0; k < mxf->metadata_sets_count; k++) {\n MXFMetadataSet *metadata = mxf->metadata_sets[k];\n if (metadata->type == CryptoContext) {\n essence_container_ul = &((MXFCryptoContext *)metadata)->source_container_ul;\n break;\n }\n }\n }", " /* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */\n codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->essence_codec_ul);\n st->codecpar->codec_id = (enum AVCodecID)codec_ul->id;\n if (st->codecpar->codec_id == AV_CODEC_ID_NONE) {\n codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->codec_ul);\n st->codecpar->codec_id = (enum AVCodecID)codec_ul->id;\n }", " av_log(mxf->fc, AV_LOG_VERBOSE, \"%s: Universal Label: \",\n avcodec_get_name(st->codecpar->codec_id));\n for (k = 0; k < 16; k++) {\n av_log(mxf->fc, AV_LOG_VERBOSE, \"%.2x\",\n descriptor->essence_codec_ul[k]);\n if (!(k+1 & 19) || k == 5)\n av_log(mxf->fc, AV_LOG_VERBOSE, \".\");\n }\n av_log(mxf->fc, AV_LOG_VERBOSE, \"\\n\");", " mxf_add_umid_metadata(&st->metadata, \"file_package_umid\", source_package);\n if (source_package->name && source_package->name[0])\n av_dict_set(&st->metadata, \"file_package_name\", source_package->name, 0);\n if (material_track->name && material_track->name[0])\n av_dict_set(&st->metadata, \"track_name\", material_track->name, 0);", " mxf_parse_physical_source_package(mxf, source_track, st);", " if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {\n source_track->intra_only = mxf_is_intra_only(descriptor);\n container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, essence_container_ul);\n if (st->codecpar->codec_id == AV_CODEC_ID_NONE)\n st->codecpar->codec_id = container_ul->id;\n st->codecpar->width = descriptor->width;\n st->codecpar->height = descriptor->height; /* Field height, not frame height */\n switch (descriptor->frame_layout) {\n case FullFrame:\n st->codecpar->field_order = AV_FIELD_PROGRESSIVE;\n break;\n case OneField:\n /* Every other line is stored and needs to be duplicated. */\n av_log(mxf->fc, AV_LOG_INFO, \"OneField frame layout isn't currently supported\\n\");\n break; /* The correct thing to do here is fall through, but by breaking we might be\n able to decode some streams at half the vertical resolution, rather than not al all.\n It's also for compatibility with the old behavior. */\n case MixedFields:\n break;\n case SegmentedFrame:\n st->codecpar->field_order = AV_FIELD_PROGRESSIVE;\n case SeparateFields:\n av_log(mxf->fc, AV_LOG_DEBUG, \"video_line_map: (%d, %d), field_dominance: %d\\n\",\n descriptor->video_line_map[0], descriptor->video_line_map[1],\n descriptor->field_dominance);\n if ((descriptor->video_line_map[0] > 0) && (descriptor->video_line_map[1] > 0)) {\n /* Detect coded field order from VideoLineMap:\n * (even, even) => bottom field coded first\n * (even, odd) => top field coded first\n * (odd, even) => top field coded first\n * (odd, odd) => bottom field coded first\n */\n if ((descriptor->video_line_map[0] + descriptor->video_line_map[1]) % 2) {\n switch (descriptor->field_dominance) {\n case MXF_FIELD_DOMINANCE_DEFAULT:\n case MXF_FIELD_DOMINANCE_FF:\n st->codecpar->field_order = AV_FIELD_TT;\n break;\n case MXF_FIELD_DOMINANCE_FL:\n st->codecpar->field_order = AV_FIELD_TB;\n break;\n default:\n avpriv_request_sample(mxf->fc,\n \"Field dominance %d support\",\n descriptor->field_dominance);\n }\n } else {\n switch (descriptor->field_dominance) {\n case MXF_FIELD_DOMINANCE_DEFAULT:\n case MXF_FIELD_DOMINANCE_FF:\n st->codecpar->field_order = AV_FIELD_BB;\n break;\n case MXF_FIELD_DOMINANCE_FL:\n st->codecpar->field_order = AV_FIELD_BT;\n break;\n default:\n avpriv_request_sample(mxf->fc,\n \"Field dominance %d support\",\n descriptor->field_dominance);\n }\n }\n }\n /* Turn field height into frame height. */\n st->codecpar->height *= 2;\n break;\n default:\n av_log(mxf->fc, AV_LOG_INFO, \"Unknown frame layout type: %d\\n\", descriptor->frame_layout);\n }\n if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) {\n st->codecpar->format = descriptor->pix_fmt;\n if (st->codecpar->format == AV_PIX_FMT_NONE) {\n pix_fmt_ul = mxf_get_codec_ul(ff_mxf_pixel_format_uls,\n &descriptor->essence_codec_ul);\n st->codecpar->format = (enum AVPixelFormat)pix_fmt_ul->id;\n if (st->codecpar->format== AV_PIX_FMT_NONE) {\n st->codecpar->codec_tag = mxf_get_codec_ul(ff_mxf_codec_tag_uls,\n &descriptor->essence_codec_ul)->id;\n if (!st->codecpar->codec_tag) {\n /* support files created before RP224v10 by defaulting to UYVY422\n if subsampling is 4:2:2 and component depth is 8-bit */\n if (descriptor->horiz_subsampling == 2 &&\n descriptor->vert_subsampling == 1 &&\n descriptor->component_depth == 8) {\n st->codecpar->format = AV_PIX_FMT_UYVY422;\n }\n }\n }\n }\n }\n st->need_parsing = AVSTREAM_PARSE_HEADERS;\n if (material_track->sequence->origin) {\n av_dict_set_int(&st->metadata, \"material_track_origin\", material_track->sequence->origin, 0);\n }\n if (source_track->sequence->origin) {\n av_dict_set_int(&st->metadata, \"source_track_origin\", source_track->sequence->origin, 0);\n }\n if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den)\n st->display_aspect_ratio = descriptor->aspect_ratio;\n } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {\n container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul);\n /* Only overwrite existing codec ID if it is unset or A-law, which is the default according to SMPTE RP 224. */\n if (st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW && (enum AVCodecID)container_ul->id != AV_CODEC_ID_NONE))\n st->codecpar->codec_id = (enum AVCodecID)container_ul->id;\n st->codecpar->channels = descriptor->channels;\n st->codecpar->bits_per_coded_sample = descriptor->bits_per_sample;", " if (descriptor->sample_rate.den > 0) {\n st->codecpar->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;\n avpriv_set_pts_info(st, 64, descriptor->sample_rate.den, descriptor->sample_rate.num);\n } else {\n av_log(mxf->fc, AV_LOG_WARNING, \"invalid sample rate (%d/%d) \"\n \"found for stream #%d, time base forced to 1/48000\\n\",\n descriptor->sample_rate.num, descriptor->sample_rate.den,\n st->index);\n avpriv_set_pts_info(st, 64, 1, 48000);\n }", " /* if duration is set, rescale it from EditRate to SampleRate */\n if (st->duration != AV_NOPTS_VALUE)\n st->duration = av_rescale_q(st->duration,\n av_inv_q(material_track->edit_rate),\n st->time_base);", " /* TODO: implement AV_CODEC_ID_RAWAUDIO */\n if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) {\n if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24)\n st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;\n else if (descriptor->bits_per_sample == 32)\n st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;\n } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) {\n if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24)\n st->codecpar->codec_id = AV_CODEC_ID_PCM_S24BE;\n else if (descriptor->bits_per_sample == 32)\n st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE;\n } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) {\n st->need_parsing = AVSTREAM_PARSE_FULL;\n }\n } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {\n enum AVMediaType type;\n container_ul = mxf_get_codec_ul(mxf_data_essence_container_uls, essence_container_ul);\n if (st->codecpar->codec_id == AV_CODEC_ID_NONE)\n st->codecpar->codec_id = container_ul->id;\n type = avcodec_get_type(st->codecpar->codec_id);\n if (type == AVMEDIA_TYPE_SUBTITLE)\n st->codecpar->codec_type = type;\n if (container_ul->desc)\n av_dict_set(&st->metadata, \"data_type\", container_ul->desc, 0);\n }\n if (descriptor->extradata) {\n if (!ff_alloc_extradata(st->codecpar, descriptor->extradata_size)) {\n memcpy(st->codecpar->extradata, descriptor->extradata, descriptor->extradata_size);\n }\n } else if (st->codecpar->codec_id == AV_CODEC_ID_H264) {\n int coded_width = mxf_get_codec_ul(mxf_intra_only_picture_coded_width,\n &descriptor->essence_codec_ul)->id;\n if (coded_width)\n st->codecpar->width = coded_width;\n ret = ff_generate_avci_extradata(st);\n if (ret < 0)\n return ret;\n }\n if (st->codecpar->codec_type != AVMEDIA_TYPE_DATA && source_track->wrapping != FrameWrapped) {\n /* TODO: decode timestamps */\n st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;\n }\n }", " ret = 0;\nfail_and_free:\n return ret;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 5047, "char_start": 5043, "chars": "->fc" } ], "deleted": [] }, "commit_link": "github.com/FFmpeg/FFmpeg/commit/bab0716c7f4793ec42e05a5aa7e80d82a0dd4e75", "file_name": "libavformat/mxfdec.c", "func_name": "mxf_parse_structural_metadata", "line_changes": { "added": [ { "char_end": 5121, "char_start": 5013, "line": " av_log(mxf->fc, AV_LOG_TRACE, \"could not resolve essence container data strong ref\\n\");\n", "line_no": 104 } ], "deleted": [ { "char_end": 5117, "char_start": 5013, "line": " av_log(mxf, AV_LOG_TRACE, \"could not resolve essence container data strong ref\\n\");\n", "line_no": 104 } ] }, "vul_type": "cwe-125" }
460
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void parse_hid_report_descriptor(struct gtco *device, char * report,\n\t\t\t\t\tint length)\n{\n\tstruct device *ddev = &device->intf->dev;\n\tint x, i = 0;", "\t/* Tag primitive vars */\n\t__u8 prefix;\n\t__u8 size;\n\t__u8 tag;\n\t__u8 type;\n\t__u8 data = 0;\n\t__u16 data16 = 0;\n\t__u32 data32 = 0;", "\t/* For parsing logic */\n\tint inputnum = 0;\n\t__u32 usage = 0;", "\t/* Global Values, indexed by TAG */\n\t__u32 globalval[TAG_GLOB_MAX];\n\t__u32 oldval[TAG_GLOB_MAX];", "\t/* Debug stuff */\n\tchar maintype = 'x';\n\tchar globtype[12];\n\tint indent = 0;\n\tchar indentstr[10] = \"\";", "\n\tdev_dbg(ddev, \"======>>>>>>PARSE<<<<<<======\\n\");", "\t/* Walk this report and pull out the info we need */\n\twhile (i < length) {", "\t\tprefix = report[i];", "\t\t/* Skip over prefix */\n\t\ti++;", "\n\t\t/* Determine data size and save the data in the proper variable */", "\t\tsize = PREF_SIZE(prefix);", "\t\tswitch (size) {\n\t\tcase 1:\n\t\t\tdata = report[i];\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tdata16 = get_unaligned_le16(&report[i]);\n\t\t\tbreak;", "\t\tcase 3:\n\t\t\tsize = 4;", "\t\t\tdata32 = get_unaligned_le32(&report[i]);\n\t\t\tbreak;\n\t\t}", "\t\t/* Skip size of data */\n\t\ti += size;", "\t\t/* What we do depends on the tag type */\n\t\ttag = PREF_TAG(prefix);\n\t\ttype = PREF_TYPE(prefix);\n\t\tswitch (type) {\n\t\tcase TYPE_MAIN:\n\t\t\tstrcpy(globtype, \"\");\n\t\t\tswitch (tag) {", "\t\t\tcase TAG_MAIN_INPUT:\n\t\t\t\t/*\n\t\t\t\t * The INPUT MAIN tag signifies this is\n\t\t\t\t * information from a report. We need to\n\t\t\t\t * figure out what it is and store the\n\t\t\t\t * min/max values\n\t\t\t\t */", "\t\t\t\tmaintype = 'I';\n\t\t\t\tif (data == 2)\n\t\t\t\t\tstrcpy(globtype, \"Variable\");\n\t\t\t\telse if (data == 3)\n\t\t\t\t\tstrcpy(globtype, \"Var|Const\");", "\t\t\t\tdev_dbg(ddev, \"::::: Saving Report: %d input #%d Max: 0x%X(%d) Min:0x%X(%d) of %d bits\\n\",\n\t\t\t\t\tglobalval[TAG_GLOB_REPORT_ID], inputnum,\n\t\t\t\t\tglobalval[TAG_GLOB_LOG_MAX], globalval[TAG_GLOB_LOG_MAX],\n\t\t\t\t\tglobalval[TAG_GLOB_LOG_MIN], globalval[TAG_GLOB_LOG_MIN],\n\t\t\t\t\tglobalval[TAG_GLOB_REPORT_SZ] * globalval[TAG_GLOB_REPORT_CNT]);", "\n\t\t\t\t/*\n\t\t\t\t We can assume that the first two input items\n\t\t\t\t are always the X and Y coordinates. After\n\t\t\t\t that, we look for everything else by\n\t\t\t\t local usage value\n\t\t\t\t */\n\t\t\t\tswitch (inputnum) {\n\t\t\t\tcase 0: /* X coord */\n\t\t\t\t\tdev_dbg(ddev, \"GER: X Usage: 0x%x\\n\", usage);\n\t\t\t\t\tif (device->max_X == 0) {\n\t\t\t\t\t\tdevice->max_X = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\tdevice->min_X = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 1: /* Y coord */\n\t\t\t\t\tdev_dbg(ddev, \"GER: Y Usage: 0x%x\\n\", usage);\n\t\t\t\t\tif (device->max_Y == 0) {\n\t\t\t\t\t\tdevice->max_Y = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\tdevice->min_Y = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tdefault:\n\t\t\t\t\t/* Tilt X */\n\t\t\t\t\tif (usage == DIGITIZER_USAGE_TILT_X) {\n\t\t\t\t\t\tif (device->maxtilt_X == 0) {\n\t\t\t\t\t\t\tdevice->maxtilt_X = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\t\tdevice->mintilt_X = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t\t}\n\t\t\t\t\t}", "\t\t\t\t\t/* Tilt Y */\n\t\t\t\t\tif (usage == DIGITIZER_USAGE_TILT_Y) {\n\t\t\t\t\t\tif (device->maxtilt_Y == 0) {\n\t\t\t\t\t\t\tdevice->maxtilt_Y = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\t\tdevice->mintilt_Y = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t\t}\n\t\t\t\t\t}", "\t\t\t\t\t/* Pressure */\n\t\t\t\t\tif (usage == DIGITIZER_USAGE_TIP_PRESSURE) {\n\t\t\t\t\t\tif (device->maxpressure == 0) {\n\t\t\t\t\t\t\tdevice->maxpressure = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\t\tdevice->minpressure = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t\t}\n\t\t\t\t\t}", "\t\t\t\t\tbreak;\n\t\t\t\t}", "\t\t\t\tinputnum++;\n\t\t\t\tbreak;", "\t\t\tcase TAG_MAIN_OUTPUT:\n\t\t\t\tmaintype = 'O';\n\t\t\t\tbreak;", "\t\t\tcase TAG_MAIN_FEATURE:\n\t\t\t\tmaintype = 'F';\n\t\t\t\tbreak;", "\t\t\tcase TAG_MAIN_COL_START:\n\t\t\t\tmaintype = 'S';", "\t\t\t\tif (data == 0) {\n\t\t\t\t\tdev_dbg(ddev, \"======>>>>>> Physical\\n\");\n\t\t\t\t\tstrcpy(globtype, \"Physical\");\n\t\t\t\t} else\n\t\t\t\t\tdev_dbg(ddev, \"======>>>>>>\\n\");", "\t\t\t\t/* Indent the debug output */\n\t\t\t\tindent++;\n\t\t\t\tfor (x = 0; x < indent; x++)\n\t\t\t\t\tindentstr[x] = '-';\n\t\t\t\tindentstr[x] = 0;", "\t\t\t\t/* Save global tags */\n\t\t\t\tfor (x = 0; x < TAG_GLOB_MAX; x++)\n\t\t\t\t\toldval[x] = globalval[x];", "\t\t\t\tbreak;", "\t\t\tcase TAG_MAIN_COL_END:\n\t\t\t\tdev_dbg(ddev, \"<<<<<<======\\n\");\n\t\t\t\tmaintype = 'E';\n\t\t\t\tindent--;\n\t\t\t\tfor (x = 0; x < indent; x++)\n\t\t\t\t\tindentstr[x] = '-';\n\t\t\t\tindentstr[x] = 0;", "\t\t\t\t/* Copy global tags back */\n\t\t\t\tfor (x = 0; x < TAG_GLOB_MAX; x++)\n\t\t\t\t\tglobalval[x] = oldval[x];", "\t\t\t\tbreak;\n\t\t\t}", "\t\t\tswitch (size) {\n\t\t\tcase 1:\n\t\t\t\tdev_dbg(ddev, \"%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, maintype, size, globtype, data);\n\t\t\t\tbreak;", "\t\t\tcase 2:\n\t\t\t\tdev_dbg(ddev, \"%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, maintype, size, globtype, data16);\n\t\t\t\tbreak;", "\t\t\tcase 4:\n\t\t\t\tdev_dbg(ddev, \"%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, maintype, size, globtype, data32);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbreak;", "\t\tcase TYPE_GLOBAL:\n\t\t\tswitch (tag) {\n\t\t\tcase TAG_GLOB_USAGE:\n\t\t\t\t/*\n\t\t\t\t * First time we hit the global usage tag,\n\t\t\t\t * it should tell us the type of device\n\t\t\t\t */\n\t\t\t\tif (device->usage == 0)\n\t\t\t\t\tdevice->usage = data;", "\t\t\t\tstrcpy(globtype, \"USAGE\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_LOG_MIN:\n\t\t\t\tstrcpy(globtype, \"LOG_MIN\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_LOG_MAX:\n\t\t\t\tstrcpy(globtype, \"LOG_MAX\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_PHYS_MIN:\n\t\t\t\tstrcpy(globtype, \"PHYS_MIN\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_PHYS_MAX:\n\t\t\t\tstrcpy(globtype, \"PHYS_MAX\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_UNIT_EXP:\n\t\t\t\tstrcpy(globtype, \"EXP\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_UNIT:\n\t\t\t\tstrcpy(globtype, \"UNIT\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_REPORT_SZ:\n\t\t\t\tstrcpy(globtype, \"REPORT_SZ\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_REPORT_ID:\n\t\t\t\tstrcpy(globtype, \"REPORT_ID\");\n\t\t\t\t/* New report, restart numbering */\n\t\t\t\tinputnum = 0;\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_REPORT_CNT:\n\t\t\t\tstrcpy(globtype, \"REPORT_CNT\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_PUSH:\n\t\t\t\tstrcpy(globtype, \"PUSH\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_POP:\n\t\t\t\tstrcpy(globtype, \"POP\");\n\t\t\t\tbreak;\n\t\t\t}", "\t\t\t/* Check to make sure we have a good tag number\n\t\t\t so we don't overflow array */\n\t\t\tif (tag < TAG_GLOB_MAX) {\n\t\t\t\tswitch (size) {\n\t\t\t\tcase 1:\n\t\t\t\t\tdev_dbg(ddev, \"%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\t\tindentstr, globtype, tag, size, data);\n\t\t\t\t\tglobalval[tag] = data;\n\t\t\t\t\tbreak;", "\t\t\t\tcase 2:\n\t\t\t\t\tdev_dbg(ddev, \"%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\t\tindentstr, globtype, tag, size, data16);\n\t\t\t\t\tglobalval[tag] = data16;\n\t\t\t\t\tbreak;", "\t\t\t\tcase 4:\n\t\t\t\t\tdev_dbg(ddev, \"%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\t\tindentstr, globtype, tag, size, data32);\n\t\t\t\t\tglobalval[tag] = data32;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdev_dbg(ddev, \"%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d\\n\",\n\t\t\t\t\tindentstr, tag, size);\n\t\t\t}\n\t\t\tbreak;", "\t\tcase TYPE_LOCAL:\n\t\t\tswitch (tag) {\n\t\t\tcase TAG_GLOB_USAGE:\n\t\t\t\tstrcpy(globtype, \"USAGE\");\n\t\t\t\t/* Always 1 byte */\n\t\t\t\tusage = data;\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_LOG_MIN:\n\t\t\t\tstrcpy(globtype, \"MIN\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_LOG_MAX:\n\t\t\t\tstrcpy(globtype, \"MAX\");\n\t\t\t\tbreak;", "\t\t\tdefault:\n\t\t\t\tstrcpy(globtype, \"UNKNOWN\");\n\t\t\t\tbreak;\n\t\t\t}", "\t\t\tswitch (size) {\n\t\t\tcase 1:\n\t\t\t\tdev_dbg(ddev, \"%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, globtype, size, data);\n\t\t\t\tbreak;", "\t\t\tcase 2:\n\t\t\t\tdev_dbg(ddev, \"%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, globtype, size, data16);\n\t\t\t\tbreak;", "\t\t\tcase 4:\n\t\t\t\tdev_dbg(ddev, \"%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, globtype, size, data32);\n\t\t\t\tbreak;\n\t\t\t}", "\t\t\tbreak;\n\t\t}\n\t}\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 725, "char_start": 723, "chars": "++" }, { "char_end": 814, "char_start": 807, "chars": "(1U << " }, { "char_end": 837, "char_start": 831, "chars": ") >> 1" }, { "char_end": 965, "char_start": 839, "chars": "\t\tif (i + size > length) {\n\t\t\tdev_err(ddev,\n\t\t\t\t\"Not enough data (need %d, have %d)\\n\",\n\t\t\t\ti + size, length);\n\t\t\tbreak;\n\t\t}\n\n" }, { "char_end": 1097, "char_start": 1096, "chars": ":" } ], "deleted": [ { "char_end": 755, "char_start": 723, "chars": "];\n\n\t\t/* Skip over prefix */\n\t\ti" }, { "char_end": 988, "char_start": 987, "chars": "3" }, { "char_end": 1002, "char_start": 989, "chars": "\n\t\t\tsize = 4;" } ] }, "commit_link": "github.com/torvalds/linux/commit/a50829479f58416a013a4ccca791336af3c584c7", "file_name": "drivers/input/tablet/gtco.c", "func_name": "parse_hid_report_descriptor", "line_changes": { "added": [ { "char_end": 728, "char_start": 704, "line": "\t\tprefix = report[i++];\n", "line_no": 35 }, { "char_end": 839, "char_start": 798, "line": "\t\tsize = (1U << PREF_SIZE(prefix)) >> 1;\n", "line_no": 38 }, { "char_end": 866, "char_start": 839, "line": "\t\tif (i + size > length) {\n", "line_no": 39 }, { "char_end": 883, "char_start": 866, "line": "\t\t\tdev_err(ddev,\n", "line_no": 40 }, { "char_end": 927, "char_start": 883, "line": "\t\t\t\t\"Not enough data (need %d, have %d)\\n\",\n", "line_no": 41 }, { "char_end": 950, "char_start": 927, "line": "\t\t\t\ti + size, length);\n", "line_no": 42 }, { "char_end": 960, "char_start": 950, "line": "\t\t\tbreak;\n", "line_no": 43 }, { "char_end": 964, "char_start": 960, "line": "\t\t}\n", "line_no": 44 }, { "char_end": 965, "char_start": 964, "line": "\n", "line_no": 45 }, { "char_end": 1098, "char_start": 1088, "line": "\t\tcase 4:\n", "line_no": 53 } ], "deleted": [ { "char_end": 726, "char_start": 704, "line": "\t\tprefix = report[i];\n", "line_no": 35 }, { "char_end": 727, "char_start": 726, "line": "\n", "line_no": 36 }, { "char_end": 752, "char_start": 727, "line": "\t\t/* Skip over prefix */\n", "line_no": 37 }, { "char_end": 759, "char_start": 752, "line": "\t\ti++;\n", "line_no": 38 }, { "char_end": 857, "char_start": 829, "line": "\t\tsize = PREF_SIZE(prefix);\n", "line_no": 41 }, { "char_end": 990, "char_start": 980, "line": "\t\tcase 3:\n", "line_no": 49 }, { "char_end": 1003, "char_start": 990, "line": "\t\t\tsize = 4;\n", "line_no": 50 } ] }, "vul_type": "cwe-125" }
461
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void parse_hid_report_descriptor(struct gtco *device, char * report,\n\t\t\t\t\tint length)\n{\n\tstruct device *ddev = &device->intf->dev;\n\tint x, i = 0;", "\t/* Tag primitive vars */\n\t__u8 prefix;\n\t__u8 size;\n\t__u8 tag;\n\t__u8 type;\n\t__u8 data = 0;\n\t__u16 data16 = 0;\n\t__u32 data32 = 0;", "\t/* For parsing logic */\n\tint inputnum = 0;\n\t__u32 usage = 0;", "\t/* Global Values, indexed by TAG */\n\t__u32 globalval[TAG_GLOB_MAX];\n\t__u32 oldval[TAG_GLOB_MAX];", "\t/* Debug stuff */\n\tchar maintype = 'x';\n\tchar globtype[12];\n\tint indent = 0;\n\tchar indentstr[10] = \"\";", "\n\tdev_dbg(ddev, \"======>>>>>>PARSE<<<<<<======\\n\");", "\t/* Walk this report and pull out the info we need */\n\twhile (i < length) {", "\t\tprefix = report[i++];", "\n\t\t/* Determine data size and save the data in the proper variable */", "\t\tsize = (1U << PREF_SIZE(prefix)) >> 1;\n\t\tif (i + size > length) {\n\t\t\tdev_err(ddev,\n\t\t\t\t\"Not enough data (need %d, have %d)\\n\",\n\t\t\t\ti + size, length);\n\t\t\tbreak;\n\t\t}\n", "\t\tswitch (size) {\n\t\tcase 1:\n\t\t\tdata = report[i];\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tdata16 = get_unaligned_le16(&report[i]);\n\t\t\tbreak;", "\t\tcase 4:", "\t\t\tdata32 = get_unaligned_le32(&report[i]);\n\t\t\tbreak;\n\t\t}", "\t\t/* Skip size of data */\n\t\ti += size;", "\t\t/* What we do depends on the tag type */\n\t\ttag = PREF_TAG(prefix);\n\t\ttype = PREF_TYPE(prefix);\n\t\tswitch (type) {\n\t\tcase TYPE_MAIN:\n\t\t\tstrcpy(globtype, \"\");\n\t\t\tswitch (tag) {", "\t\t\tcase TAG_MAIN_INPUT:\n\t\t\t\t/*\n\t\t\t\t * The INPUT MAIN tag signifies this is\n\t\t\t\t * information from a report. We need to\n\t\t\t\t * figure out what it is and store the\n\t\t\t\t * min/max values\n\t\t\t\t */", "\t\t\t\tmaintype = 'I';\n\t\t\t\tif (data == 2)\n\t\t\t\t\tstrcpy(globtype, \"Variable\");\n\t\t\t\telse if (data == 3)\n\t\t\t\t\tstrcpy(globtype, \"Var|Const\");", "\t\t\t\tdev_dbg(ddev, \"::::: Saving Report: %d input #%d Max: 0x%X(%d) Min:0x%X(%d) of %d bits\\n\",\n\t\t\t\t\tglobalval[TAG_GLOB_REPORT_ID], inputnum,\n\t\t\t\t\tglobalval[TAG_GLOB_LOG_MAX], globalval[TAG_GLOB_LOG_MAX],\n\t\t\t\t\tglobalval[TAG_GLOB_LOG_MIN], globalval[TAG_GLOB_LOG_MIN],\n\t\t\t\t\tglobalval[TAG_GLOB_REPORT_SZ] * globalval[TAG_GLOB_REPORT_CNT]);", "\n\t\t\t\t/*\n\t\t\t\t We can assume that the first two input items\n\t\t\t\t are always the X and Y coordinates. After\n\t\t\t\t that, we look for everything else by\n\t\t\t\t local usage value\n\t\t\t\t */\n\t\t\t\tswitch (inputnum) {\n\t\t\t\tcase 0: /* X coord */\n\t\t\t\t\tdev_dbg(ddev, \"GER: X Usage: 0x%x\\n\", usage);\n\t\t\t\t\tif (device->max_X == 0) {\n\t\t\t\t\t\tdevice->max_X = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\tdevice->min_X = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 1: /* Y coord */\n\t\t\t\t\tdev_dbg(ddev, \"GER: Y Usage: 0x%x\\n\", usage);\n\t\t\t\t\tif (device->max_Y == 0) {\n\t\t\t\t\t\tdevice->max_Y = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\tdevice->min_Y = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tdefault:\n\t\t\t\t\t/* Tilt X */\n\t\t\t\t\tif (usage == DIGITIZER_USAGE_TILT_X) {\n\t\t\t\t\t\tif (device->maxtilt_X == 0) {\n\t\t\t\t\t\t\tdevice->maxtilt_X = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\t\tdevice->mintilt_X = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t\t}\n\t\t\t\t\t}", "\t\t\t\t\t/* Tilt Y */\n\t\t\t\t\tif (usage == DIGITIZER_USAGE_TILT_Y) {\n\t\t\t\t\t\tif (device->maxtilt_Y == 0) {\n\t\t\t\t\t\t\tdevice->maxtilt_Y = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\t\tdevice->mintilt_Y = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t\t}\n\t\t\t\t\t}", "\t\t\t\t\t/* Pressure */\n\t\t\t\t\tif (usage == DIGITIZER_USAGE_TIP_PRESSURE) {\n\t\t\t\t\t\tif (device->maxpressure == 0) {\n\t\t\t\t\t\t\tdevice->maxpressure = globalval[TAG_GLOB_LOG_MAX];\n\t\t\t\t\t\t\tdevice->minpressure = globalval[TAG_GLOB_LOG_MIN];\n\t\t\t\t\t\t}\n\t\t\t\t\t}", "\t\t\t\t\tbreak;\n\t\t\t\t}", "\t\t\t\tinputnum++;\n\t\t\t\tbreak;", "\t\t\tcase TAG_MAIN_OUTPUT:\n\t\t\t\tmaintype = 'O';\n\t\t\t\tbreak;", "\t\t\tcase TAG_MAIN_FEATURE:\n\t\t\t\tmaintype = 'F';\n\t\t\t\tbreak;", "\t\t\tcase TAG_MAIN_COL_START:\n\t\t\t\tmaintype = 'S';", "\t\t\t\tif (data == 0) {\n\t\t\t\t\tdev_dbg(ddev, \"======>>>>>> Physical\\n\");\n\t\t\t\t\tstrcpy(globtype, \"Physical\");\n\t\t\t\t} else\n\t\t\t\t\tdev_dbg(ddev, \"======>>>>>>\\n\");", "\t\t\t\t/* Indent the debug output */\n\t\t\t\tindent++;\n\t\t\t\tfor (x = 0; x < indent; x++)\n\t\t\t\t\tindentstr[x] = '-';\n\t\t\t\tindentstr[x] = 0;", "\t\t\t\t/* Save global tags */\n\t\t\t\tfor (x = 0; x < TAG_GLOB_MAX; x++)\n\t\t\t\t\toldval[x] = globalval[x];", "\t\t\t\tbreak;", "\t\t\tcase TAG_MAIN_COL_END:\n\t\t\t\tdev_dbg(ddev, \"<<<<<<======\\n\");\n\t\t\t\tmaintype = 'E';\n\t\t\t\tindent--;\n\t\t\t\tfor (x = 0; x < indent; x++)\n\t\t\t\t\tindentstr[x] = '-';\n\t\t\t\tindentstr[x] = 0;", "\t\t\t\t/* Copy global tags back */\n\t\t\t\tfor (x = 0; x < TAG_GLOB_MAX; x++)\n\t\t\t\t\tglobalval[x] = oldval[x];", "\t\t\t\tbreak;\n\t\t\t}", "\t\t\tswitch (size) {\n\t\t\tcase 1:\n\t\t\t\tdev_dbg(ddev, \"%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, maintype, size, globtype, data);\n\t\t\t\tbreak;", "\t\t\tcase 2:\n\t\t\t\tdev_dbg(ddev, \"%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, maintype, size, globtype, data16);\n\t\t\t\tbreak;", "\t\t\tcase 4:\n\t\t\t\tdev_dbg(ddev, \"%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, maintype, size, globtype, data32);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbreak;", "\t\tcase TYPE_GLOBAL:\n\t\t\tswitch (tag) {\n\t\t\tcase TAG_GLOB_USAGE:\n\t\t\t\t/*\n\t\t\t\t * First time we hit the global usage tag,\n\t\t\t\t * it should tell us the type of device\n\t\t\t\t */\n\t\t\t\tif (device->usage == 0)\n\t\t\t\t\tdevice->usage = data;", "\t\t\t\tstrcpy(globtype, \"USAGE\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_LOG_MIN:\n\t\t\t\tstrcpy(globtype, \"LOG_MIN\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_LOG_MAX:\n\t\t\t\tstrcpy(globtype, \"LOG_MAX\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_PHYS_MIN:\n\t\t\t\tstrcpy(globtype, \"PHYS_MIN\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_PHYS_MAX:\n\t\t\t\tstrcpy(globtype, \"PHYS_MAX\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_UNIT_EXP:\n\t\t\t\tstrcpy(globtype, \"EXP\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_UNIT:\n\t\t\t\tstrcpy(globtype, \"UNIT\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_REPORT_SZ:\n\t\t\t\tstrcpy(globtype, \"REPORT_SZ\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_REPORT_ID:\n\t\t\t\tstrcpy(globtype, \"REPORT_ID\");\n\t\t\t\t/* New report, restart numbering */\n\t\t\t\tinputnum = 0;\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_REPORT_CNT:\n\t\t\t\tstrcpy(globtype, \"REPORT_CNT\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_PUSH:\n\t\t\t\tstrcpy(globtype, \"PUSH\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_POP:\n\t\t\t\tstrcpy(globtype, \"POP\");\n\t\t\t\tbreak;\n\t\t\t}", "\t\t\t/* Check to make sure we have a good tag number\n\t\t\t so we don't overflow array */\n\t\t\tif (tag < TAG_GLOB_MAX) {\n\t\t\t\tswitch (size) {\n\t\t\t\tcase 1:\n\t\t\t\t\tdev_dbg(ddev, \"%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\t\tindentstr, globtype, tag, size, data);\n\t\t\t\t\tglobalval[tag] = data;\n\t\t\t\t\tbreak;", "\t\t\t\tcase 2:\n\t\t\t\t\tdev_dbg(ddev, \"%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\t\tindentstr, globtype, tag, size, data16);\n\t\t\t\t\tglobalval[tag] = data16;\n\t\t\t\t\tbreak;", "\t\t\t\tcase 4:\n\t\t\t\t\tdev_dbg(ddev, \"%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\t\tindentstr, globtype, tag, size, data32);\n\t\t\t\t\tglobalval[tag] = data32;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdev_dbg(ddev, \"%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d\\n\",\n\t\t\t\t\tindentstr, tag, size);\n\t\t\t}\n\t\t\tbreak;", "\t\tcase TYPE_LOCAL:\n\t\t\tswitch (tag) {\n\t\t\tcase TAG_GLOB_USAGE:\n\t\t\t\tstrcpy(globtype, \"USAGE\");\n\t\t\t\t/* Always 1 byte */\n\t\t\t\tusage = data;\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_LOG_MIN:\n\t\t\t\tstrcpy(globtype, \"MIN\");\n\t\t\t\tbreak;", "\t\t\tcase TAG_GLOB_LOG_MAX:\n\t\t\t\tstrcpy(globtype, \"MAX\");\n\t\t\t\tbreak;", "\t\t\tdefault:\n\t\t\t\tstrcpy(globtype, \"UNKNOWN\");\n\t\t\t\tbreak;\n\t\t\t}", "\t\t\tswitch (size) {\n\t\t\tcase 1:\n\t\t\t\tdev_dbg(ddev, \"%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, globtype, size, data);\n\t\t\t\tbreak;", "\t\t\tcase 2:\n\t\t\t\tdev_dbg(ddev, \"%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, globtype, size, data16);\n\t\t\t\tbreak;", "\t\t\tcase 4:\n\t\t\t\tdev_dbg(ddev, \"%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\\n\",\n\t\t\t\t\tindentstr, tag, globtype, size, data32);\n\t\t\t\tbreak;\n\t\t\t}", "\t\t\tbreak;\n\t\t}\n\t}\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 725, "char_start": 723, "chars": "++" }, { "char_end": 814, "char_start": 807, "chars": "(1U << " }, { "char_end": 837, "char_start": 831, "chars": ") >> 1" }, { "char_end": 965, "char_start": 839, "chars": "\t\tif (i + size > length) {\n\t\t\tdev_err(ddev,\n\t\t\t\t\"Not enough data (need %d, have %d)\\n\",\n\t\t\t\ti + size, length);\n\t\t\tbreak;\n\t\t}\n\n" }, { "char_end": 1097, "char_start": 1096, "chars": ":" } ], "deleted": [ { "char_end": 755, "char_start": 723, "chars": "];\n\n\t\t/* Skip over prefix */\n\t\ti" }, { "char_end": 988, "char_start": 987, "chars": "3" }, { "char_end": 1002, "char_start": 989, "chars": "\n\t\t\tsize = 4;" } ] }, "commit_link": "github.com/torvalds/linux/commit/a50829479f58416a013a4ccca791336af3c584c7", "file_name": "drivers/input/tablet/gtco.c", "func_name": "parse_hid_report_descriptor", "line_changes": { "added": [ { "char_end": 728, "char_start": 704, "line": "\t\tprefix = report[i++];\n", "line_no": 35 }, { "char_end": 839, "char_start": 798, "line": "\t\tsize = (1U << PREF_SIZE(prefix)) >> 1;\n", "line_no": 38 }, { "char_end": 866, "char_start": 839, "line": "\t\tif (i + size > length) {\n", "line_no": 39 }, { "char_end": 883, "char_start": 866, "line": "\t\t\tdev_err(ddev,\n", "line_no": 40 }, { "char_end": 927, "char_start": 883, "line": "\t\t\t\t\"Not enough data (need %d, have %d)\\n\",\n", "line_no": 41 }, { "char_end": 950, "char_start": 927, "line": "\t\t\t\ti + size, length);\n", "line_no": 42 }, { "char_end": 960, "char_start": 950, "line": "\t\t\tbreak;\n", "line_no": 43 }, { "char_end": 964, "char_start": 960, "line": "\t\t}\n", "line_no": 44 }, { "char_end": 965, "char_start": 964, "line": "\n", "line_no": 45 }, { "char_end": 1098, "char_start": 1088, "line": "\t\tcase 4:\n", "line_no": 53 } ], "deleted": [ { "char_end": 726, "char_start": 704, "line": "\t\tprefix = report[i];\n", "line_no": 35 }, { "char_end": 727, "char_start": 726, "line": "\n", "line_no": 36 }, { "char_end": 752, "char_start": 727, "line": "\t\t/* Skip over prefix */\n", "line_no": 37 }, { "char_end": 759, "char_start": 752, "line": "\t\ti++;\n", "line_no": 38 }, { "char_end": 857, "char_start": 829, "line": "\t\tsize = PREF_SIZE(prefix);\n", "line_no": 41 }, { "char_end": 990, "char_start": 980, "line": "\t\tcase 3:\n", "line_no": 49 }, { "char_end": 1003, "char_start": 990, "line": "\t\t\tsize = 4;\n", "line_no": 50 } ] }, "vul_type": "cwe-125" }
461
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "int fpm_log_write(char *log_format) /* {{{ */\n{\n\tchar *s, *b;\n\tchar buffer[FPM_LOG_BUFFER+1];\n\tint token, test;\n\tsize_t len, len2;\n\tstruct fpm_scoreboard_proc_s proc, *proc_p;\n\tstruct fpm_scoreboard_s *scoreboard;\n\tchar tmp[129];\n\tchar format[129];\n\ttime_t now_epoch;\n#ifdef HAVE_TIMES\n\tclock_t tms_total;\n#endif", "\tif (!log_format && (!fpm_log_format || fpm_log_fd == -1)) {\n\t\treturn -1;\n\t}", "\tif (!log_format) {\n\t\tlog_format = fpm_log_format;\n\t\ttest = 0;\n\t} else {\n\t\ttest = 1;\n\t}", "\tnow_epoch = time(NULL);", "\tif (!test) {\n\t\tscoreboard = fpm_scoreboard_get();\n\t\tif (!scoreboard) {\n\t\t\tzlog(ZLOG_WARNING, \"unable to get scoreboard while preparing the access log\");\n\t\t\treturn -1;\n\t\t}\n\t\tproc_p = fpm_scoreboard_proc_acquire(NULL, -1, 0);\n\t\tif (!proc_p) {\n\t\t\tzlog(ZLOG_WARNING, \"[pool %s] Unable to acquire shm slot while preparing the access log\", scoreboard->pool);\n\t\t\treturn -1;\n\t\t}\n\t\tproc = *proc_p;\n\t\tfpm_scoreboard_proc_release(proc_p);\n\t}", "\ttoken = 0;", "\tmemset(buffer, '\\0', sizeof(buffer));\n\tb = buffer;\n\tlen = 0;", "\n\ts = log_format;", "\twhile (*s != '\\0') {\n\t\t/* Test is we have place for 1 more char. */\n\t\tif (len >= FPM_LOG_BUFFER) {\n\t\t\tzlog(ZLOG_NOTICE, \"the log buffer is full (%d). The access log request has been truncated.\", FPM_LOG_BUFFER);\n\t\t\tlen = FPM_LOG_BUFFER;\n\t\t\tbreak;\n\t\t}", "\t\tif (!token && *s == '%') {\n\t\t\ttoken = 1;\n\t\t\tmemset(format, '\\0', sizeof(format)); /* reset format */\n\t\t\ts++;\n\t\t\tcontinue;\n\t\t}", "\t\tif (token) {\n\t\t\ttoken = 0;\n\t\t\tlen2 = 0;\n\t\t\tswitch (*s) {", "\t\t\t\tcase '%': /* '%' */\n\t\t\t\t\t*b = '%';\n\t\t\t\t\tlen2 = 1;\n\t\t\t\t\tbreak;", "#ifdef HAVE_TIMES\n\t\t\t\tcase 'C': /* %CPU */\n\t\t\t\t\tif (format[0] == '\\0' || !strcasecmp(format, \"total\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\ttms_total = proc.last_request_cpu.tms_utime + proc.last_request_cpu.tms_stime + proc.last_request_cpu.tms_cutime + proc.last_request_cpu.tms_cstime;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!strcasecmp(format, \"user\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\ttms_total = proc.last_request_cpu.tms_utime + proc.last_request_cpu.tms_cutime;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!strcasecmp(format, \"system\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\ttms_total = proc.last_request_cpu.tms_stime + proc.last_request_cpu.tms_cstime;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"only 'total', 'user' or 'system' are allowed as a modifier for %%%c ('%s')\", *s, format);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}", "\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%.2f\", tms_total / fpm_scoreboard_get_tick() / (proc.cpu_duration.tv_sec + proc.cpu_duration.tv_usec / 1000000.) * 100.);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n#endif", "\t\t\t\tcase 'd': /* duration µs */\n\t\t\t\t\t/* seconds */\n\t\t\t\t\tif (format[0] == '\\0' || !strcasecmp(format, \"seconds\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%.3f\", proc.duration.tv_sec + proc.duration.tv_usec / 1000000.);\n\t\t\t\t\t\t}", "\t\t\t\t\t/* miliseconds */\n\t\t\t\t\t} else if (!strcasecmp(format, \"miliseconds\") || !strcasecmp(format, \"mili\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%.3f\", proc.duration.tv_sec * 1000. + proc.duration.tv_usec / 1000.);\n\t\t\t\t\t\t}", "\t\t\t\t\t/* microseconds */\n\t\t\t\t\t} else if (!strcasecmp(format, \"microseconds\") || !strcasecmp(format, \"micro\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%lu\", proc.duration.tv_sec * 1000000UL + proc.duration.tv_usec);\n\t\t\t\t\t\t}", "\t\t\t\t\t} else {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"only 'seconds', 'mili', 'miliseconds', 'micro' or 'microseconds' are allowed as a modifier for %%%c ('%s')\", *s, format);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'e': /* fastcgi env */\n\t\t\t\t\tif (format[0] == '\\0') {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"the name of the environment variable must be set between embraces for %%%c\", *s);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}", "\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tchar *env = fcgi_getenv((fcgi_request*) SG(server_context), format, strlen(format));\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", env ? env : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'f': /* script */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", *proc.script_filename ? proc.script_filename : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'l': /* content length */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%zu\", proc.content_length);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'm': /* method */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", *proc.request_method ? proc.request_method : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'M': /* memory */\n\t\t\t\t\t/* seconds */\n\t\t\t\t\tif (format[0] == '\\0' || !strcasecmp(format, \"bytes\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%zu\", proc.memory);\n\t\t\t\t\t\t}", "\t\t\t\t\t/* kilobytes */\n\t\t\t\t\t} else if (!strcasecmp(format, \"kilobytes\") || !strcasecmp(format, \"kilo\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%lu\", proc.memory / 1024);\n\t\t\t\t\t\t}", "\t\t\t\t\t/* megabytes */\n\t\t\t\t\t} else if (!strcasecmp(format, \"megabytes\") || !strcasecmp(format, \"mega\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%lu\", proc.memory / 1024 / 1024);\n\t\t\t\t\t\t}", "\t\t\t\t\t} else {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"only 'bytes', 'kilo', 'kilobytes', 'mega' or 'megabytes' are allowed as a modifier for %%%c ('%s')\", *s, format);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'n': /* pool name */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", scoreboard->pool[0] ? scoreboard->pool : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'o': /* header output */\n\t\t\t\t\tif (format[0] == '\\0') {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"the name of the header must be set between embraces for %%%c\", *s);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tsapi_header_struct *h;\n\t\t\t\t\t\tzend_llist_position pos;\n\t\t\t\t\t\tsapi_headers_struct *sapi_headers = &SG(sapi_headers);\n\t\t\t\t\t\tsize_t format_len = strlen(format);", "\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\twhile (h) {\n\t\t\t\t\t\t\tchar *header;\n\t\t\t\t\t\t\tif (!h->header_len) {\n\t\t\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!strstr(h->header, format)) {\n\t\t\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}", "\t\t\t\t\t\t\t/* test if enought char after the header name + ': ' */\n\t\t\t\t\t\t\tif (h->header_len <= format_len + 2) {\n\t\t\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}", "\t\t\t\t\t\t\tif (h->header[format_len] != ':' || h->header[format_len + 1] != ' ') {\n\t\t\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}", "\t\t\t\t\t\t\theader = h->header + format_len + 2;\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", header && *header ? header : \"-\");", "\t\t\t\t\t\t\t/* found, done */\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!len2) {\n\t\t\t\t\t\t\tlen2 = 1;\n\t\t\t\t\t\t\t*b = '-';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'p': /* PID */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%ld\", (long)getpid());\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'P': /* PID */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%ld\", (long)getppid());\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'q': /* query_string */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", proc.query_string);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'Q': /* '?' */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", *proc.query_string ? \"?\" : \"\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'r': /* request URI */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", proc.request_uri);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'R': /* remote IP address */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tconst char *tmp = fcgi_get_last_client_ip();\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", tmp ? tmp : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 's': /* status */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%d\", SG(sapi_headers).http_response_code);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'T':\n\t\t\t\tcase 't': /* time */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\ttime_t *t;\n\t\t\t\t\t\tif (*s == 't') {\n\t\t\t\t\t\t\tt = &proc.accepted_epoch;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tt = &now_epoch;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (format[0] == '\\0') {\n\t\t\t\t\t\t\tstrftime(tmp, sizeof(tmp) - 1, \"%d/%b/%Y:%H:%M:%S %z\", localtime(t));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstrftime(tmp, sizeof(tmp) - 1, format, localtime(t));\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", tmp);\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'u': /* remote user */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", proc.auth_user);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase '{': /* complex var */\n\t\t\t\t\ttoken = 1;\n\t\t\t\t\t{\n\t\t\t\t\t\tchar *start;\n\t\t\t\t\t\tsize_t l;", "\t\t\t\t\t\tstart = ++s;", "\t\t\t\t\t\twhile (*s != '\\0') {\n\t\t\t\t\t\t\tif (*s == '}') {\n\t\t\t\t\t\t\t\tl = s - start;", "\t\t\t\t\t\t\t\tif (l >= sizeof(format) - 1) {\n\t\t\t\t\t\t\t\t\tl = sizeof(format) - 1;\n\t\t\t\t\t\t\t\t}", "\t\t\t\t\t\t\t\tmemcpy(format, start, l);\n\t\t\t\t\t\t\t\tformat[l] = '\\0';\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ts++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (s[1] == '\\0') {\n\t\t\t\t\t\t\tzlog(ZLOG_WARNING, \"missing closing embrace in the access.format\");\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tdefault:\n\t\t\t\t\tzlog(ZLOG_WARNING, \"Invalid token in the access.format (%%%c)\", *s);\n\t\t\t\t\treturn -1;\n\t\t\t}", "\t\t\tif (*s != '}' && format[0] != '\\0') {\n\t\t\t\tzlog(ZLOG_WARNING, \"embrace is not allowed for modifier %%%c\", *s);\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ts++;\n\t\t\tif (!test) {\n\t\t\t\tb += len2;\n\t\t\t\tlen += len2;\n\t\t\t}", "", "\t\t\tcontinue;\n\t\t}", "\t\tif (!test) {\n\t\t\t// push the normal char to the output buffer\n\t\t\t*b = *s;\n\t\t\tb++;\n\t\t\tlen++;\n\t\t}\n\t\ts++;\n\t}", "\tif (!test && strlen(buffer) > 0) {\n\t\tbuffer[len] = '\\n';\n\t\twrite(fpm_log_fd, buffer, len + 1);\n\t}", "\treturn 0;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 9626, "char_start": 9438, "chars": "if (len >= FPM_LOG_BUFFER) {\n\t\t\t\tzlog(ZLOG_NOTICE, \"the log buffer is full (%d). The access log request has been truncated.\", FPM_LOG_BUFFER);\n\t\t\t\tlen = FPM_LOG_BUFFER;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t" } ], "deleted": [] }, "commit_link": "github.com/php/php-src/commit/2721a0148649e07ed74468f097a28899741eb58f", "file_name": "sapi/fpm/fpm/fpm_log.c", "func_name": "fpm_log_write", "line_changes": { "added": [ { "char_end": 9467, "char_start": 9435, "line": "\t\t\tif (len >= FPM_LOG_BUFFER) {\n", "line_no": 352 }, { "char_end": 9581, "char_start": 9467, "line": "\t\t\t\tzlog(ZLOG_NOTICE, \"the log buffer is full (%d). The access log request has been truncated.\", FPM_LOG_BUFFER);\n", "line_no": 353 }, { "char_end": 9607, "char_start": 9581, "line": "\t\t\t\tlen = FPM_LOG_BUFFER;\n", "line_no": 354 }, { "char_end": 9618, "char_start": 9607, "line": "\t\t\t\tbreak;\n", "line_no": 355 }, { "char_end": 9623, "char_start": 9618, "line": "\t\t\t}\n", "line_no": 356 } ], "deleted": [] }, "vul_type": "cwe-125" }
462
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "int fpm_log_write(char *log_format) /* {{{ */\n{\n\tchar *s, *b;\n\tchar buffer[FPM_LOG_BUFFER+1];\n\tint token, test;\n\tsize_t len, len2;\n\tstruct fpm_scoreboard_proc_s proc, *proc_p;\n\tstruct fpm_scoreboard_s *scoreboard;\n\tchar tmp[129];\n\tchar format[129];\n\ttime_t now_epoch;\n#ifdef HAVE_TIMES\n\tclock_t tms_total;\n#endif", "\tif (!log_format && (!fpm_log_format || fpm_log_fd == -1)) {\n\t\treturn -1;\n\t}", "\tif (!log_format) {\n\t\tlog_format = fpm_log_format;\n\t\ttest = 0;\n\t} else {\n\t\ttest = 1;\n\t}", "\tnow_epoch = time(NULL);", "\tif (!test) {\n\t\tscoreboard = fpm_scoreboard_get();\n\t\tif (!scoreboard) {\n\t\t\tzlog(ZLOG_WARNING, \"unable to get scoreboard while preparing the access log\");\n\t\t\treturn -1;\n\t\t}\n\t\tproc_p = fpm_scoreboard_proc_acquire(NULL, -1, 0);\n\t\tif (!proc_p) {\n\t\t\tzlog(ZLOG_WARNING, \"[pool %s] Unable to acquire shm slot while preparing the access log\", scoreboard->pool);\n\t\t\treturn -1;\n\t\t}\n\t\tproc = *proc_p;\n\t\tfpm_scoreboard_proc_release(proc_p);\n\t}", "\ttoken = 0;", "\tmemset(buffer, '\\0', sizeof(buffer));\n\tb = buffer;\n\tlen = 0;", "\n\ts = log_format;", "\twhile (*s != '\\0') {\n\t\t/* Test is we have place for 1 more char. */\n\t\tif (len >= FPM_LOG_BUFFER) {\n\t\t\tzlog(ZLOG_NOTICE, \"the log buffer is full (%d). The access log request has been truncated.\", FPM_LOG_BUFFER);\n\t\t\tlen = FPM_LOG_BUFFER;\n\t\t\tbreak;\n\t\t}", "\t\tif (!token && *s == '%') {\n\t\t\ttoken = 1;\n\t\t\tmemset(format, '\\0', sizeof(format)); /* reset format */\n\t\t\ts++;\n\t\t\tcontinue;\n\t\t}", "\t\tif (token) {\n\t\t\ttoken = 0;\n\t\t\tlen2 = 0;\n\t\t\tswitch (*s) {", "\t\t\t\tcase '%': /* '%' */\n\t\t\t\t\t*b = '%';\n\t\t\t\t\tlen2 = 1;\n\t\t\t\t\tbreak;", "#ifdef HAVE_TIMES\n\t\t\t\tcase 'C': /* %CPU */\n\t\t\t\t\tif (format[0] == '\\0' || !strcasecmp(format, \"total\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\ttms_total = proc.last_request_cpu.tms_utime + proc.last_request_cpu.tms_stime + proc.last_request_cpu.tms_cutime + proc.last_request_cpu.tms_cstime;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!strcasecmp(format, \"user\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\ttms_total = proc.last_request_cpu.tms_utime + proc.last_request_cpu.tms_cutime;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!strcasecmp(format, \"system\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\ttms_total = proc.last_request_cpu.tms_stime + proc.last_request_cpu.tms_cstime;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"only 'total', 'user' or 'system' are allowed as a modifier for %%%c ('%s')\", *s, format);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}", "\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%.2f\", tms_total / fpm_scoreboard_get_tick() / (proc.cpu_duration.tv_sec + proc.cpu_duration.tv_usec / 1000000.) * 100.);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n#endif", "\t\t\t\tcase 'd': /* duration µs */\n\t\t\t\t\t/* seconds */\n\t\t\t\t\tif (format[0] == '\\0' || !strcasecmp(format, \"seconds\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%.3f\", proc.duration.tv_sec + proc.duration.tv_usec / 1000000.);\n\t\t\t\t\t\t}", "\t\t\t\t\t/* miliseconds */\n\t\t\t\t\t} else if (!strcasecmp(format, \"miliseconds\") || !strcasecmp(format, \"mili\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%.3f\", proc.duration.tv_sec * 1000. + proc.duration.tv_usec / 1000.);\n\t\t\t\t\t\t}", "\t\t\t\t\t/* microseconds */\n\t\t\t\t\t} else if (!strcasecmp(format, \"microseconds\") || !strcasecmp(format, \"micro\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%lu\", proc.duration.tv_sec * 1000000UL + proc.duration.tv_usec);\n\t\t\t\t\t\t}", "\t\t\t\t\t} else {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"only 'seconds', 'mili', 'miliseconds', 'micro' or 'microseconds' are allowed as a modifier for %%%c ('%s')\", *s, format);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'e': /* fastcgi env */\n\t\t\t\t\tif (format[0] == '\\0') {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"the name of the environment variable must be set between embraces for %%%c\", *s);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}", "\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tchar *env = fcgi_getenv((fcgi_request*) SG(server_context), format, strlen(format));\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", env ? env : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'f': /* script */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", *proc.script_filename ? proc.script_filename : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'l': /* content length */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%zu\", proc.content_length);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'm': /* method */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", *proc.request_method ? proc.request_method : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'M': /* memory */\n\t\t\t\t\t/* seconds */\n\t\t\t\t\tif (format[0] == '\\0' || !strcasecmp(format, \"bytes\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%zu\", proc.memory);\n\t\t\t\t\t\t}", "\t\t\t\t\t/* kilobytes */\n\t\t\t\t\t} else if (!strcasecmp(format, \"kilobytes\") || !strcasecmp(format, \"kilo\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%lu\", proc.memory / 1024);\n\t\t\t\t\t\t}", "\t\t\t\t\t/* megabytes */\n\t\t\t\t\t} else if (!strcasecmp(format, \"megabytes\") || !strcasecmp(format, \"mega\")) {\n\t\t\t\t\t\tif (!test) {\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%lu\", proc.memory / 1024 / 1024);\n\t\t\t\t\t\t}", "\t\t\t\t\t} else {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"only 'bytes', 'kilo', 'kilobytes', 'mega' or 'megabytes' are allowed as a modifier for %%%c ('%s')\", *s, format);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'n': /* pool name */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", scoreboard->pool[0] ? scoreboard->pool : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'o': /* header output */\n\t\t\t\t\tif (format[0] == '\\0') {\n\t\t\t\t\t\tzlog(ZLOG_WARNING, \"the name of the header must be set between embraces for %%%c\", *s);\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tsapi_header_struct *h;\n\t\t\t\t\t\tzend_llist_position pos;\n\t\t\t\t\t\tsapi_headers_struct *sapi_headers = &SG(sapi_headers);\n\t\t\t\t\t\tsize_t format_len = strlen(format);", "\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\twhile (h) {\n\t\t\t\t\t\t\tchar *header;\n\t\t\t\t\t\t\tif (!h->header_len) {\n\t\t\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!strstr(h->header, format)) {\n\t\t\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}", "\t\t\t\t\t\t\t/* test if enought char after the header name + ': ' */\n\t\t\t\t\t\t\tif (h->header_len <= format_len + 2) {\n\t\t\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}", "\t\t\t\t\t\t\tif (h->header[format_len] != ':' || h->header[format_len + 1] != ' ') {\n\t\t\t\t\t\t\t\th = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}", "\t\t\t\t\t\t\theader = h->header + format_len + 2;\n\t\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", header && *header ? header : \"-\");", "\t\t\t\t\t\t\t/* found, done */\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!len2) {\n\t\t\t\t\t\t\tlen2 = 1;\n\t\t\t\t\t\t\t*b = '-';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'p': /* PID */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%ld\", (long)getpid());\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'P': /* PID */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%ld\", (long)getppid());\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'q': /* query_string */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", proc.query_string);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'Q': /* '?' */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", *proc.query_string ? \"?\" : \"\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'r': /* request URI */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", proc.request_uri);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'R': /* remote IP address */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tconst char *tmp = fcgi_get_last_client_ip();\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", tmp ? tmp : \"-\");\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 's': /* status */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%d\", SG(sapi_headers).http_response_code);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'T':\n\t\t\t\tcase 't': /* time */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\ttime_t *t;\n\t\t\t\t\t\tif (*s == 't') {\n\t\t\t\t\t\t\tt = &proc.accepted_epoch;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tt = &now_epoch;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (format[0] == '\\0') {\n\t\t\t\t\t\t\tstrftime(tmp, sizeof(tmp) - 1, \"%d/%b/%Y:%H:%M:%S %z\", localtime(t));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstrftime(tmp, sizeof(tmp) - 1, format, localtime(t));\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", tmp);\n\t\t\t\t\t}\n\t\t\t\t\tformat[0] = '\\0';\n\t\t\t\t\tbreak;", "\t\t\t\tcase 'u': /* remote user */\n\t\t\t\t\tif (!test) {\n\t\t\t\t\t\tlen2 = snprintf(b, FPM_LOG_BUFFER - len, \"%s\", proc.auth_user);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tcase '{': /* complex var */\n\t\t\t\t\ttoken = 1;\n\t\t\t\t\t{\n\t\t\t\t\t\tchar *start;\n\t\t\t\t\t\tsize_t l;", "\t\t\t\t\t\tstart = ++s;", "\t\t\t\t\t\twhile (*s != '\\0') {\n\t\t\t\t\t\t\tif (*s == '}') {\n\t\t\t\t\t\t\t\tl = s - start;", "\t\t\t\t\t\t\t\tif (l >= sizeof(format) - 1) {\n\t\t\t\t\t\t\t\t\tl = sizeof(format) - 1;\n\t\t\t\t\t\t\t\t}", "\t\t\t\t\t\t\t\tmemcpy(format, start, l);\n\t\t\t\t\t\t\t\tformat[l] = '\\0';\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ts++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (s[1] == '\\0') {\n\t\t\t\t\t\t\tzlog(ZLOG_WARNING, \"missing closing embrace in the access.format\");\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;", "\t\t\t\tdefault:\n\t\t\t\t\tzlog(ZLOG_WARNING, \"Invalid token in the access.format (%%%c)\", *s);\n\t\t\t\t\treturn -1;\n\t\t\t}", "\t\t\tif (*s != '}' && format[0] != '\\0') {\n\t\t\t\tzlog(ZLOG_WARNING, \"embrace is not allowed for modifier %%%c\", *s);\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ts++;\n\t\t\tif (!test) {\n\t\t\t\tb += len2;\n\t\t\t\tlen += len2;\n\t\t\t}", "\t\t\tif (len >= FPM_LOG_BUFFER) {\n\t\t\t\tzlog(ZLOG_NOTICE, \"the log buffer is full (%d). The access log request has been truncated.\", FPM_LOG_BUFFER);\n\t\t\t\tlen = FPM_LOG_BUFFER;\n\t\t\t\tbreak;\n\t\t\t}", "\t\t\tcontinue;\n\t\t}", "\t\tif (!test) {\n\t\t\t// push the normal char to the output buffer\n\t\t\t*b = *s;\n\t\t\tb++;\n\t\t\tlen++;\n\t\t}\n\t\ts++;\n\t}", "\tif (!test && strlen(buffer) > 0) {\n\t\tbuffer[len] = '\\n';\n\t\twrite(fpm_log_fd, buffer, len + 1);\n\t}", "\treturn 0;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 9626, "char_start": 9438, "chars": "if (len >= FPM_LOG_BUFFER) {\n\t\t\t\tzlog(ZLOG_NOTICE, \"the log buffer is full (%d). The access log request has been truncated.\", FPM_LOG_BUFFER);\n\t\t\t\tlen = FPM_LOG_BUFFER;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t" } ], "deleted": [] }, "commit_link": "github.com/php/php-src/commit/2721a0148649e07ed74468f097a28899741eb58f", "file_name": "sapi/fpm/fpm/fpm_log.c", "func_name": "fpm_log_write", "line_changes": { "added": [ { "char_end": 9467, "char_start": 9435, "line": "\t\t\tif (len >= FPM_LOG_BUFFER) {\n", "line_no": 352 }, { "char_end": 9581, "char_start": 9467, "line": "\t\t\t\tzlog(ZLOG_NOTICE, \"the log buffer is full (%d). The access log request has been truncated.\", FPM_LOG_BUFFER);\n", "line_no": 353 }, { "char_end": 9607, "char_start": 9581, "line": "\t\t\t\tlen = FPM_LOG_BUFFER;\n", "line_no": 354 }, { "char_end": 9618, "char_start": 9607, "line": "\t\t\t\tbreak;\n", "line_no": 355 }, { "char_end": 9623, "char_start": 9618, "line": "\t\t\t}\n", "line_no": 356 } ], "deleted": [] }, "vul_type": "cwe-125" }
462
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static MagickBooleanType load_tile(Image *image,Image *tile_image,\n XCFDocInfo *inDocInfo,XCFLayerInfo *inLayerInfo,size_t data_length,\n ExceptionInfo *exception)\n{\n ssize_t\n y;", " register ssize_t\n x;", " register Quantum\n *q;", " ssize_t\n count;", " unsigned char\n *graydata;", " XCFPixelInfo\n *xcfdata,\n *xcfodata;\n", " xcfdata=(XCFPixelInfo *) AcquireQuantumMemory(data_length,sizeof(*xcfdata));", " if (xcfdata == (XCFPixelInfo *) NULL)\n ThrowBinaryException(ResourceLimitError,\"MemoryAllocationFailed\",\n image->filename);\n xcfodata=xcfdata;\n graydata=(unsigned char *) xcfdata; /* used by gray and indexed */\n count=ReadBlob(image,data_length,(unsigned char *) xcfdata);\n if (count != (ssize_t) data_length)\n ThrowBinaryException(CorruptImageError,\"NotEnoughPixelData\",\n image->filename);\n for (y=0; y < (ssize_t) tile_image->rows; y++)\n {\n q=GetAuthenticPixels(tile_image,0,y,tile_image->columns,1,exception);\n if (q == (Quantum *) NULL)\n break;\n if (inDocInfo->image_type == GIMP_GRAY)\n {\n for (x=0; x < (ssize_t) tile_image->columns; x++)\n {\n SetPixelGray(tile_image,ScaleCharToQuantum(*graydata),q);\n SetPixelAlpha(tile_image,ScaleCharToQuantum((unsigned char)\n inLayerInfo->alpha),q);\n graydata++;\n q+=GetPixelChannels(tile_image);\n }\n }\n else\n if (inDocInfo->image_type == GIMP_RGB)\n {\n for (x=0; x < (ssize_t) tile_image->columns; x++)\n {\n SetPixelRed(tile_image,ScaleCharToQuantum(xcfdata->red),q);\n SetPixelGreen(tile_image,ScaleCharToQuantum(xcfdata->green),q);\n SetPixelBlue(tile_image,ScaleCharToQuantum(xcfdata->blue),q);\n SetPixelAlpha(tile_image,xcfdata->alpha == 255U ? TransparentAlpha :\n ScaleCharToQuantum((unsigned char) inLayerInfo->alpha),q);\n xcfdata++;\n q+=GetPixelChannels(tile_image);\n }\n }\n if (SyncAuthenticPixels(tile_image,exception) == MagickFalse)\n break;\n }\n xcfodata=(XCFPixelInfo *) RelinquishMagickMemory(xcfodata);\n return MagickTrue;\n}" ]
[ 1, 1, 1, 1, 1, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 397, "char_start": 387, "chars": "MagickMax(" }, { "char_end": 451, "char_start": 408, "chars": ",\n tile_image->columns*tile_image->rows)" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/a2e1064f288a353bc5fef7f79ccb7683759e775c", "file_name": "coders/xcf.c", "func_name": "load_tile", "line_changes": { "added": [ { "char_end": 410, "char_start": 339, "line": " xcfdata=(XCFPixelInfo *) AcquireQuantumMemory(MagickMax(data_length,\n", "line_no": 24 }, { "char_end": 471, "char_start": 410, "line": " tile_image->columns*tile_image->rows),sizeof(*xcfdata));\n", "line_no": 25 } ], "deleted": [ { "char_end": 418, "char_start": 339, "line": " xcfdata=(XCFPixelInfo *) AcquireQuantumMemory(data_length,sizeof(*xcfdata));\n", "line_no": 24 } ] }, "vul_type": "cwe-125" }
463
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static MagickBooleanType load_tile(Image *image,Image *tile_image,\n XCFDocInfo *inDocInfo,XCFLayerInfo *inLayerInfo,size_t data_length,\n ExceptionInfo *exception)\n{\n ssize_t\n y;", " register ssize_t\n x;", " register Quantum\n *q;", " ssize_t\n count;", " unsigned char\n *graydata;", " XCFPixelInfo\n *xcfdata,\n *xcfodata;\n", " xcfdata=(XCFPixelInfo *) AcquireQuantumMemory(MagickMax(data_length,\n tile_image->columns*tile_image->rows),sizeof(*xcfdata));", " if (xcfdata == (XCFPixelInfo *) NULL)\n ThrowBinaryException(ResourceLimitError,\"MemoryAllocationFailed\",\n image->filename);\n xcfodata=xcfdata;\n graydata=(unsigned char *) xcfdata; /* used by gray and indexed */\n count=ReadBlob(image,data_length,(unsigned char *) xcfdata);\n if (count != (ssize_t) data_length)\n ThrowBinaryException(CorruptImageError,\"NotEnoughPixelData\",\n image->filename);\n for (y=0; y < (ssize_t) tile_image->rows; y++)\n {\n q=GetAuthenticPixels(tile_image,0,y,tile_image->columns,1,exception);\n if (q == (Quantum *) NULL)\n break;\n if (inDocInfo->image_type == GIMP_GRAY)\n {\n for (x=0; x < (ssize_t) tile_image->columns; x++)\n {\n SetPixelGray(tile_image,ScaleCharToQuantum(*graydata),q);\n SetPixelAlpha(tile_image,ScaleCharToQuantum((unsigned char)\n inLayerInfo->alpha),q);\n graydata++;\n q+=GetPixelChannels(tile_image);\n }\n }\n else\n if (inDocInfo->image_type == GIMP_RGB)\n {\n for (x=0; x < (ssize_t) tile_image->columns; x++)\n {\n SetPixelRed(tile_image,ScaleCharToQuantum(xcfdata->red),q);\n SetPixelGreen(tile_image,ScaleCharToQuantum(xcfdata->green),q);\n SetPixelBlue(tile_image,ScaleCharToQuantum(xcfdata->blue),q);\n SetPixelAlpha(tile_image,xcfdata->alpha == 255U ? TransparentAlpha :\n ScaleCharToQuantum((unsigned char) inLayerInfo->alpha),q);\n xcfdata++;\n q+=GetPixelChannels(tile_image);\n }\n }\n if (SyncAuthenticPixels(tile_image,exception) == MagickFalse)\n break;\n }\n xcfodata=(XCFPixelInfo *) RelinquishMagickMemory(xcfodata);\n return MagickTrue;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 397, "char_start": 387, "chars": "MagickMax(" }, { "char_end": 451, "char_start": 408, "chars": ",\n tile_image->columns*tile_image->rows)" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/a2e1064f288a353bc5fef7f79ccb7683759e775c", "file_name": "coders/xcf.c", "func_name": "load_tile", "line_changes": { "added": [ { "char_end": 410, "char_start": 339, "line": " xcfdata=(XCFPixelInfo *) AcquireQuantumMemory(MagickMax(data_length,\n", "line_no": 24 }, { "char_end": 471, "char_start": 410, "line": " tile_image->columns*tile_image->rows),sizeof(*xcfdata));\n", "line_no": 25 } ], "deleted": [ { "char_end": 418, "char_start": 339, "line": " xcfdata=(XCFPixelInfo *) AcquireQuantumMemory(data_length,sizeof(*xcfdata));\n", "line_no": 24 } ] }, "vul_type": "cwe-125" }
463
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void hid_input_field(struct hid_device *hid, struct hid_field *field,\n\t\t\t __u8 *data, int interrupt)\n{\n\tunsigned n;\n\tunsigned count = field->report_count;\n\tunsigned offset = field->report_offset;\n\tunsigned size = field->report_size;\n\t__s32 min = field->logical_minimum;\n\t__s32 max = field->logical_maximum;\n\t__s32 *value;", "\tvalue = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);\n\tif (!value)\n\t\treturn;", "\tfor (n = 0; n < count; n++) {", "\t\tvalue[n] = min < 0 ?\n\t\t\tsnto32(hid_field_extract(hid, data, offset + n * size,\n\t\t\t size), size) :\n\t\t\thid_field_extract(hid, data, offset + n * size, size);", "\t\t/* Ignore report if ErrorRollOver */\n\t\tif (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&\n\t\t value[n] >= min && value[n] <= max &&", "", "\t\t field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)\n\t\t\tgoto exit;\n\t}", "\tfor (n = 0; n < count; n++) {", "\t\tif (HID_MAIN_ITEM_VARIABLE & field->flags) {\n\t\t\thid_process_event(hid, field, &field->usage[n], value[n], interrupt);\n\t\t\tcontinue;\n\t\t}", "\t\tif (field->value[n] >= min && field->value[n] <= max", "", "\t\t\t&& field->usage[field->value[n] - min].hid\n\t\t\t&& search(value, field->value[n], count))\n\t\t\t\thid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);", "\t\tif (value[n] >= min && value[n] <= max", "", "\t\t\t&& field->usage[value[n] - min].hid\n\t\t\t&& search(field->value, value[n], count))\n\t\t\t\thid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);\n\t}", "\tmemcpy(field->value, value, count * sizeof(__s32));\nexit:\n\tkfree(value);\n}" ]
[ 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 788, "char_start": 746, "chars": "value[n] - min < field->maxusage &&\n\t\t " }, { "char_end": 1134, "char_start": 1088, "chars": "\t\t\t&& field->value[n] - min < field->maxusage\n" }, { "char_end": 1392, "char_start": 1353, "chars": "\n\t\t\t&& value[n] - min < field->maxusage" } ], "deleted": [ { "char_end": 803, "char_start": 803, "chars": "" }, { "char_end": 1225, "char_start": 1225, "chars": "" } ] }, "commit_link": "github.com/torvalds/linux/commit/50220dead1650609206efe91f0cc116132d59b3f", "file_name": "drivers/hid/hid-core.c", "func_name": "hid_input_field", "line_changes": { "added": [ { "char_end": 782, "char_start": 740, "line": "\t\t value[n] - min < field->maxusage &&\n", "line_no": 26 }, { "char_end": 1134, "char_start": 1088, "line": "\t\t\t&& field->value[n] - min < field->maxusage\n", "line_no": 39 }, { "char_end": 1393, "char_start": 1354, "line": "\t\t\t&& value[n] - min < field->maxusage\n", "line_no": 45 } ], "deleted": [] }, "vul_type": "cwe-125" }
464
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void hid_input_field(struct hid_device *hid, struct hid_field *field,\n\t\t\t __u8 *data, int interrupt)\n{\n\tunsigned n;\n\tunsigned count = field->report_count;\n\tunsigned offset = field->report_offset;\n\tunsigned size = field->report_size;\n\t__s32 min = field->logical_minimum;\n\t__s32 max = field->logical_maximum;\n\t__s32 *value;", "\tvalue = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);\n\tif (!value)\n\t\treturn;", "\tfor (n = 0; n < count; n++) {", "\t\tvalue[n] = min < 0 ?\n\t\t\tsnto32(hid_field_extract(hid, data, offset + n * size,\n\t\t\t size), size) :\n\t\t\thid_field_extract(hid, data, offset + n * size, size);", "\t\t/* Ignore report if ErrorRollOver */\n\t\tif (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&\n\t\t value[n] >= min && value[n] <= max &&", "\t\t value[n] - min < field->maxusage &&", "\t\t field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)\n\t\t\tgoto exit;\n\t}", "\tfor (n = 0; n < count; n++) {", "\t\tif (HID_MAIN_ITEM_VARIABLE & field->flags) {\n\t\t\thid_process_event(hid, field, &field->usage[n], value[n], interrupt);\n\t\t\tcontinue;\n\t\t}", "\t\tif (field->value[n] >= min && field->value[n] <= max", "\t\t\t&& field->value[n] - min < field->maxusage", "\t\t\t&& field->usage[field->value[n] - min].hid\n\t\t\t&& search(value, field->value[n], count))\n\t\t\t\thid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);", "\t\tif (value[n] >= min && value[n] <= max", "\t\t\t&& value[n] - min < field->maxusage", "\t\t\t&& field->usage[value[n] - min].hid\n\t\t\t&& search(field->value, value[n], count))\n\t\t\t\thid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);\n\t}", "\tmemcpy(field->value, value, count * sizeof(__s32));\nexit:\n\tkfree(value);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 788, "char_start": 746, "chars": "value[n] - min < field->maxusage &&\n\t\t " }, { "char_end": 1134, "char_start": 1088, "chars": "\t\t\t&& field->value[n] - min < field->maxusage\n" }, { "char_end": 1392, "char_start": 1353, "chars": "\n\t\t\t&& value[n] - min < field->maxusage" } ], "deleted": [ { "char_end": 803, "char_start": 803, "chars": "" }, { "char_end": 1225, "char_start": 1225, "chars": "" } ] }, "commit_link": "github.com/torvalds/linux/commit/50220dead1650609206efe91f0cc116132d59b3f", "file_name": "drivers/hid/hid-core.c", "func_name": "hid_input_field", "line_changes": { "added": [ { "char_end": 782, "char_start": 740, "line": "\t\t value[n] - min < field->maxusage &&\n", "line_no": 26 }, { "char_end": 1134, "char_start": 1088, "line": "\t\t\t&& field->value[n] - min < field->maxusage\n", "line_no": 39 }, { "char_end": 1393, "char_start": 1354, "line": "\t\t\t&& value[n] - min < field->maxusage\n", "line_no": 45 } ], "deleted": [] }, "vul_type": "cwe-125" }
464
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void gmc_mmx(uint8_t *dst, uint8_t *src,\n int stride, int h, int ox, int oy,\n int dxx, int dxy, int dyx, int dyy,\n int shift, int r, int width, int height)\n{\n const int w = 8;\n const int ix = ox >> (16 + shift);\n const int iy = oy >> (16 + shift);\n const int oxs = ox >> 4;\n const int oys = oy >> 4;\n const int dxxs = dxx >> 4;\n const int dxys = dxy >> 4;\n const int dyxs = dyx >> 4;\n const int dyys = dyy >> 4;\n const uint16_t r4[4] = { r, r, r, r };\n const uint16_t dxy4[4] = { dxys, dxys, dxys, dxys };\n const uint16_t dyy4[4] = { dyys, dyys, dyys, dyys };\n const uint64_t shift2 = 2 * shift;\n#define MAX_STRIDE 4096U\n#define MAX_H 8U\n uint8_t edge_buf[(MAX_H + 1) * MAX_STRIDE];\n int x, y;", " const int dxw = (dxx - (1 << (16 + shift))) * (w - 1);\n const int dyh = (dyy - (1 << (16 + shift))) * (h - 1);\n const int dxh = dxy * (h - 1);\n const int dyw = dyx * (w - 1);", " int need_emu = (unsigned) ix >= width - w ||\n (unsigned) iy >= height - h;", "\n if ( // non-constant fullpel offset (3% of blocks)\n ((ox ^ (ox + dxw)) | (ox ^ (ox + dxh)) | (ox ^ (ox + dxw + dxh)) |\n (oy ^ (oy + dyw)) | (oy ^ (oy + dyh)) | (oy ^ (oy + dyw + dyh))) >> (16 + shift) ||\n // uses more than 16 bits of subpel mv (only at huge resolution)\n (dxx | dxy | dyx | dyy) & 15 ||\n (need_emu && (h > MAX_H || stride > MAX_STRIDE))) {\n // FIXME could still use mmx for some of the rows\n ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy,\n shift, r, width, height);\n return;\n }", " src += ix + iy * stride;\n if (need_emu) {\n ff_emulated_edge_mc_8(edge_buf, src, stride, stride, w + 1, h + 1, ix, iy, width, height);\n src = edge_buf;\n }", " __asm__ volatile (\n \"movd %0, %%mm6 \\n\\t\"\n \"pxor %%mm7, %%mm7 \\n\\t\"\n \"punpcklwd %%mm6, %%mm6 \\n\\t\"\n \"punpcklwd %%mm6, %%mm6 \\n\\t\"\n :: \"r\" (1 << shift));", " for (x = 0; x < w; x += 4) {\n uint16_t dx4[4] = { oxs - dxys + dxxs * (x + 0),\n oxs - dxys + dxxs * (x + 1),\n oxs - dxys + dxxs * (x + 2),\n oxs - dxys + dxxs * (x + 3) };\n uint16_t dy4[4] = { oys - dyys + dyxs * (x + 0),\n oys - dyys + dyxs * (x + 1),\n oys - dyys + dyxs * (x + 2),\n oys - dyys + dyxs * (x + 3) };", " for (y = 0; y < h; y++) {\n __asm__ volatile (\n \"movq %0, %%mm4 \\n\\t\"\n \"movq %1, %%mm5 \\n\\t\"\n \"paddw %2, %%mm4 \\n\\t\"\n \"paddw %3, %%mm5 \\n\\t\"\n \"movq %%mm4, %0 \\n\\t\"\n \"movq %%mm5, %1 \\n\\t\"\n \"psrlw $12, %%mm4 \\n\\t\"\n \"psrlw $12, %%mm5 \\n\\t\"\n : \"+m\" (*dx4), \"+m\" (*dy4)\n : \"m\" (*dxy4), \"m\" (*dyy4));", " __asm__ volatile (\n \"movq %%mm6, %%mm2 \\n\\t\"\n \"movq %%mm6, %%mm1 \\n\\t\"\n \"psubw %%mm4, %%mm2 \\n\\t\"\n \"psubw %%mm5, %%mm1 \\n\\t\"\n \"movq %%mm2, %%mm0 \\n\\t\"\n \"movq %%mm4, %%mm3 \\n\\t\"\n \"pmullw %%mm1, %%mm0 \\n\\t\" // (s - dx) * (s - dy)\n \"pmullw %%mm5, %%mm3 \\n\\t\" // dx * dy\n \"pmullw %%mm5, %%mm2 \\n\\t\" // (s - dx) * dy\n \"pmullw %%mm4, %%mm1 \\n\\t\" // dx * (s - dy)", " \"movd %4, %%mm5 \\n\\t\"\n \"movd %3, %%mm4 \\n\\t\"\n \"punpcklbw %%mm7, %%mm5 \\n\\t\"\n \"punpcklbw %%mm7, %%mm4 \\n\\t\"\n \"pmullw %%mm5, %%mm3 \\n\\t\" // src[1, 1] * dx * dy\n \"pmullw %%mm4, %%mm2 \\n\\t\" // src[0, 1] * (s - dx) * dy", " \"movd %2, %%mm5 \\n\\t\"\n \"movd %1, %%mm4 \\n\\t\"\n \"punpcklbw %%mm7, %%mm5 \\n\\t\"\n \"punpcklbw %%mm7, %%mm4 \\n\\t\"\n \"pmullw %%mm5, %%mm1 \\n\\t\" // src[1, 0] * dx * (s - dy)\n \"pmullw %%mm4, %%mm0 \\n\\t\" // src[0, 0] * (s - dx) * (s - dy)\n \"paddw %5, %%mm1 \\n\\t\"\n \"paddw %%mm3, %%mm2 \\n\\t\"\n \"paddw %%mm1, %%mm0 \\n\\t\"\n \"paddw %%mm2, %%mm0 \\n\\t\"", " \"psrlw %6, %%mm0 \\n\\t\"\n \"packuswb %%mm0, %%mm0 \\n\\t\"\n \"movd %%mm0, %0 \\n\\t\"", " : \"=m\" (dst[x + y * stride])\n : \"m\" (src[0]), \"m\" (src[1]),\n \"m\" (src[stride]), \"m\" (src[stride + 1]),\n \"m\" (*r4), \"m\" (shift2));\n src += stride;\n }\n src += 4 - h * stride;\n }\n}" ]
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1072, "char_start": 1059, "chars": " width < w ||" }, { "char_end": 1156, "char_start": 1121, "chars": " || height< h\n " } ], "deleted": [] }, "commit_link": "github.com/FFmpeg/FFmpeg/commit/58cf31cee7a456057f337b3102a03206d833d5e8", "file_name": "libavcodec/x86/mpegvideodsp.c", "func_name": "gmc_mmx", "line_changes": { "added": [ { "char_end": 1073, "char_start": 1008, "line": " int need_emu = (unsigned) ix >= width - w || width < w ||\n", "line_no": 28 }, { "char_end": 1135, "char_start": 1073, "line": " (unsigned) iy >= height - h || height< h\n", "line_no": 29 }, { "char_end": 1158, "char_start": 1135, "line": " ;\n", "line_no": 30 } ], "deleted": [ { "char_end": 1060, "char_start": 1008, "line": " int need_emu = (unsigned) ix >= width - w ||\n", "line_no": 28 }, { "char_end": 1110, "char_start": 1060, "line": " (unsigned) iy >= height - h;\n", "line_no": 29 } ] }, "vul_type": "cwe-125" }
465
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void gmc_mmx(uint8_t *dst, uint8_t *src,\n int stride, int h, int ox, int oy,\n int dxx, int dxy, int dyx, int dyy,\n int shift, int r, int width, int height)\n{\n const int w = 8;\n const int ix = ox >> (16 + shift);\n const int iy = oy >> (16 + shift);\n const int oxs = ox >> 4;\n const int oys = oy >> 4;\n const int dxxs = dxx >> 4;\n const int dxys = dxy >> 4;\n const int dyxs = dyx >> 4;\n const int dyys = dyy >> 4;\n const uint16_t r4[4] = { r, r, r, r };\n const uint16_t dxy4[4] = { dxys, dxys, dxys, dxys };\n const uint16_t dyy4[4] = { dyys, dyys, dyys, dyys };\n const uint64_t shift2 = 2 * shift;\n#define MAX_STRIDE 4096U\n#define MAX_H 8U\n uint8_t edge_buf[(MAX_H + 1) * MAX_STRIDE];\n int x, y;", " const int dxw = (dxx - (1 << (16 + shift))) * (w - 1);\n const int dyh = (dyy - (1 << (16 + shift))) * (h - 1);\n const int dxh = dxy * (h - 1);\n const int dyw = dyx * (w - 1);", " int need_emu = (unsigned) ix >= width - w || width < w ||\n (unsigned) iy >= height - h || height< h\n ;", "\n if ( // non-constant fullpel offset (3% of blocks)\n ((ox ^ (ox + dxw)) | (ox ^ (ox + dxh)) | (ox ^ (ox + dxw + dxh)) |\n (oy ^ (oy + dyw)) | (oy ^ (oy + dyh)) | (oy ^ (oy + dyw + dyh))) >> (16 + shift) ||\n // uses more than 16 bits of subpel mv (only at huge resolution)\n (dxx | dxy | dyx | dyy) & 15 ||\n (need_emu && (h > MAX_H || stride > MAX_STRIDE))) {\n // FIXME could still use mmx for some of the rows\n ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy,\n shift, r, width, height);\n return;\n }", " src += ix + iy * stride;\n if (need_emu) {\n ff_emulated_edge_mc_8(edge_buf, src, stride, stride, w + 1, h + 1, ix, iy, width, height);\n src = edge_buf;\n }", " __asm__ volatile (\n \"movd %0, %%mm6 \\n\\t\"\n \"pxor %%mm7, %%mm7 \\n\\t\"\n \"punpcklwd %%mm6, %%mm6 \\n\\t\"\n \"punpcklwd %%mm6, %%mm6 \\n\\t\"\n :: \"r\" (1 << shift));", " for (x = 0; x < w; x += 4) {\n uint16_t dx4[4] = { oxs - dxys + dxxs * (x + 0),\n oxs - dxys + dxxs * (x + 1),\n oxs - dxys + dxxs * (x + 2),\n oxs - dxys + dxxs * (x + 3) };\n uint16_t dy4[4] = { oys - dyys + dyxs * (x + 0),\n oys - dyys + dyxs * (x + 1),\n oys - dyys + dyxs * (x + 2),\n oys - dyys + dyxs * (x + 3) };", " for (y = 0; y < h; y++) {\n __asm__ volatile (\n \"movq %0, %%mm4 \\n\\t\"\n \"movq %1, %%mm5 \\n\\t\"\n \"paddw %2, %%mm4 \\n\\t\"\n \"paddw %3, %%mm5 \\n\\t\"\n \"movq %%mm4, %0 \\n\\t\"\n \"movq %%mm5, %1 \\n\\t\"\n \"psrlw $12, %%mm4 \\n\\t\"\n \"psrlw $12, %%mm5 \\n\\t\"\n : \"+m\" (*dx4), \"+m\" (*dy4)\n : \"m\" (*dxy4), \"m\" (*dyy4));", " __asm__ volatile (\n \"movq %%mm6, %%mm2 \\n\\t\"\n \"movq %%mm6, %%mm1 \\n\\t\"\n \"psubw %%mm4, %%mm2 \\n\\t\"\n \"psubw %%mm5, %%mm1 \\n\\t\"\n \"movq %%mm2, %%mm0 \\n\\t\"\n \"movq %%mm4, %%mm3 \\n\\t\"\n \"pmullw %%mm1, %%mm0 \\n\\t\" // (s - dx) * (s - dy)\n \"pmullw %%mm5, %%mm3 \\n\\t\" // dx * dy\n \"pmullw %%mm5, %%mm2 \\n\\t\" // (s - dx) * dy\n \"pmullw %%mm4, %%mm1 \\n\\t\" // dx * (s - dy)", " \"movd %4, %%mm5 \\n\\t\"\n \"movd %3, %%mm4 \\n\\t\"\n \"punpcklbw %%mm7, %%mm5 \\n\\t\"\n \"punpcklbw %%mm7, %%mm4 \\n\\t\"\n \"pmullw %%mm5, %%mm3 \\n\\t\" // src[1, 1] * dx * dy\n \"pmullw %%mm4, %%mm2 \\n\\t\" // src[0, 1] * (s - dx) * dy", " \"movd %2, %%mm5 \\n\\t\"\n \"movd %1, %%mm4 \\n\\t\"\n \"punpcklbw %%mm7, %%mm5 \\n\\t\"\n \"punpcklbw %%mm7, %%mm4 \\n\\t\"\n \"pmullw %%mm5, %%mm1 \\n\\t\" // src[1, 0] * dx * (s - dy)\n \"pmullw %%mm4, %%mm0 \\n\\t\" // src[0, 0] * (s - dx) * (s - dy)\n \"paddw %5, %%mm1 \\n\\t\"\n \"paddw %%mm3, %%mm2 \\n\\t\"\n \"paddw %%mm1, %%mm0 \\n\\t\"\n \"paddw %%mm2, %%mm0 \\n\\t\"", " \"psrlw %6, %%mm0 \\n\\t\"\n \"packuswb %%mm0, %%mm0 \\n\\t\"\n \"movd %%mm0, %0 \\n\\t\"", " : \"=m\" (dst[x + y * stride])\n : \"m\" (src[0]), \"m\" (src[1]),\n \"m\" (src[stride]), \"m\" (src[stride + 1]),\n \"m\" (*r4), \"m\" (shift2));\n src += stride;\n }\n src += 4 - h * stride;\n }\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1072, "char_start": 1059, "chars": " width < w ||" }, { "char_end": 1156, "char_start": 1121, "chars": " || height< h\n " } ], "deleted": [] }, "commit_link": "github.com/FFmpeg/FFmpeg/commit/58cf31cee7a456057f337b3102a03206d833d5e8", "file_name": "libavcodec/x86/mpegvideodsp.c", "func_name": "gmc_mmx", "line_changes": { "added": [ { "char_end": 1073, "char_start": 1008, "line": " int need_emu = (unsigned) ix >= width - w || width < w ||\n", "line_no": 28 }, { "char_end": 1135, "char_start": 1073, "line": " (unsigned) iy >= height - h || height< h\n", "line_no": 29 }, { "char_end": 1158, "char_start": 1135, "line": " ;\n", "line_no": 30 } ], "deleted": [ { "char_end": 1060, "char_start": 1008, "line": " int need_emu = (unsigned) ix >= width - w ||\n", "line_no": 28 }, { "char_end": 1110, "char_start": 1060, "line": " (unsigned) iy >= height - h;\n", "line_no": 29 } ] }, "vul_type": "cwe-125" }
465
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iter_t *field)\n{\n#ifndef PB_ENABLE_MALLOC\n PB_UNUSED(wire_type);\n PB_UNUSED(field);\n PB_RETURN_ERROR(stream, \"no malloc support\");\n#else\n switch (PB_HTYPE(field->type))\n {\n case PB_HTYPE_REQUIRED:\n case PB_HTYPE_OPTIONAL:\n case PB_HTYPE_ONEOF:\n if (!check_wire_type(wire_type, field))\n PB_RETURN_ERROR(stream, \"wrong wire type\");", " if (PB_LTYPE_IS_SUBMSG(field->type) && *(void**)field->pField != NULL)\n {\n /* Duplicate field, have to release the old allocation first. */\n /* FIXME: Does this work correctly for oneofs? */\n pb_release_single_field(field);\n }\n \n if (PB_HTYPE(field->type) == PB_HTYPE_ONEOF)\n {\n *(pb_size_t*)field->pSize = field->tag;\n }", " if (PB_LTYPE(field->type) == PB_LTYPE_STRING ||\n PB_LTYPE(field->type) == PB_LTYPE_BYTES)\n {\n /* pb_dec_string and pb_dec_bytes handle allocation themselves */\n field->pData = field->pField;\n return decode_basic_field(stream, field);\n }\n else\n {\n if (!allocate_field(stream, field->pField, field->data_size, 1))\n return false;\n \n field->pData = *(void**)field->pField;\n initialize_pointer_field(field->pData, field);\n return decode_basic_field(stream, field);\n }\n \n case PB_HTYPE_REPEATED:\n if (wire_type == PB_WT_STRING\n && PB_LTYPE(field->type) <= PB_LTYPE_LAST_PACKABLE)\n {\n /* Packed array, multiple items come in at once. */\n bool status = true;\n pb_size_t *size = (pb_size_t*)field->pSize;\n size_t allocated_size = *size;\n pb_istream_t substream;\n \n if (!pb_make_string_substream(stream, &substream))\n return false;\n \n while (substream.bytes_left)\n {\n if ((size_t)*size + 1 > allocated_size)\n {\n /* Allocate more storage. This tries to guess the\n * number of remaining entries. Round the division\n * upwards. */\n allocated_size += (substream.bytes_left - 1) / field->data_size + 1;\n \n if (!allocate_field(&substream, field->pField, field->data_size, allocated_size))\n {\n status = false;\n break;\n }\n }", " /* Decode the array entry */\n field->pData = *(char**)field->pField + field->data_size * (*size);\n initialize_pointer_field(field->pData, field);\n if (!decode_basic_field(&substream, field))\n {\n status = false;\n break;\n }\n \n if (*size == PB_SIZE_MAX)\n {\n#ifndef PB_NO_ERRMSG\n stream->errmsg = \"too many array entries\";\n#endif\n status = false;\n break;\n }\n \n (*size)++;\n }\n if (!pb_close_string_substream(stream, &substream))\n return false;\n \n return status;\n }\n else\n {\n /* Normal repeated field, i.e. only one item at a time. */\n pb_size_t *size = (pb_size_t*)field->pSize;", " if (*size == PB_SIZE_MAX)\n PB_RETURN_ERROR(stream, \"too many array entries\");\n \n if (!check_wire_type(wire_type, field))\n PB_RETURN_ERROR(stream, \"wrong wire type\");\n", " (*size)++;\n if (!allocate_field(stream, field->pField, field->data_size, *size))", " return false;\n ", " field->pData = *(char**)field->pField + field->data_size * (*size - 1);", " initialize_pointer_field(field->pData, field);\n return decode_basic_field(stream, field);\n }", " default:\n PB_RETURN_ERROR(stream, \"invalid field type\");\n }\n#endif\n}" ]
[ 1, 1, 1, 1, 1, 0, 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 4292, "char_start": 4283, "chars": "(size_t)(" }, { "char_end": 4302, "char_start": 4297, "chars": " + 1)" }, { "char_end": 4440, "char_start": 4433, "chars": ");\n " }, { "char_end": 4443, "char_start": 4441, "chars": " " }, { "char_end": 4458, "char_start": 4444, "chars": " (*size" }, { "char_end": 4461, "char_start": 4459, "chars": "++" } ], "deleted": [ { "char_end": 4249, "char_start": 4222, "chars": "(*size)++;\n " }, { "char_end": 4448, "char_start": 4447, "chars": "-" }, { "char_end": 4450, "char_start": 4449, "chars": "1" } ] }, "commit_link": "github.com/nanopb/nanopb/commit/45582f1f97f49e2abfdba1463d1e1027682d9856", "file_name": "pb_decode.c", "func_name": "decode_pointer_field", "line_changes": { "added": [ { "char_end": 4305, "char_start": 4206, "line": " if (!allocate_field(stream, field->pField, field->data_size, (size_t)(*size + 1)))\n", "line_no": 110 }, { "char_end": 4436, "char_start": 4352, "line": " field->pData = *(char**)field->pField + field->data_size * (*size);\n", "line_no": 113 }, { "char_end": 4463, "char_start": 4436, "line": " (*size)++;\n", "line_no": 114 } ], "deleted": [ { "char_end": 4233, "char_start": 4206, "line": " (*size)++;\n", "line_no": 110 }, { "char_end": 4318, "char_start": 4233, "line": " if (!allocate_field(stream, field->pField, field->data_size, *size))\n", "line_no": 111 }, { "char_end": 4453, "char_start": 4365, "line": " field->pData = *(char**)field->pField + field->data_size * (*size - 1);\n", "line_no": 114 } ] }, "vul_type": "cwe-125" }
466
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iter_t *field)\n{\n#ifndef PB_ENABLE_MALLOC\n PB_UNUSED(wire_type);\n PB_UNUSED(field);\n PB_RETURN_ERROR(stream, \"no malloc support\");\n#else\n switch (PB_HTYPE(field->type))\n {\n case PB_HTYPE_REQUIRED:\n case PB_HTYPE_OPTIONAL:\n case PB_HTYPE_ONEOF:\n if (!check_wire_type(wire_type, field))\n PB_RETURN_ERROR(stream, \"wrong wire type\");", " if (PB_LTYPE_IS_SUBMSG(field->type) && *(void**)field->pField != NULL)\n {\n /* Duplicate field, have to release the old allocation first. */\n /* FIXME: Does this work correctly for oneofs? */\n pb_release_single_field(field);\n }\n \n if (PB_HTYPE(field->type) == PB_HTYPE_ONEOF)\n {\n *(pb_size_t*)field->pSize = field->tag;\n }", " if (PB_LTYPE(field->type) == PB_LTYPE_STRING ||\n PB_LTYPE(field->type) == PB_LTYPE_BYTES)\n {\n /* pb_dec_string and pb_dec_bytes handle allocation themselves */\n field->pData = field->pField;\n return decode_basic_field(stream, field);\n }\n else\n {\n if (!allocate_field(stream, field->pField, field->data_size, 1))\n return false;\n \n field->pData = *(void**)field->pField;\n initialize_pointer_field(field->pData, field);\n return decode_basic_field(stream, field);\n }\n \n case PB_HTYPE_REPEATED:\n if (wire_type == PB_WT_STRING\n && PB_LTYPE(field->type) <= PB_LTYPE_LAST_PACKABLE)\n {\n /* Packed array, multiple items come in at once. */\n bool status = true;\n pb_size_t *size = (pb_size_t*)field->pSize;\n size_t allocated_size = *size;\n pb_istream_t substream;\n \n if (!pb_make_string_substream(stream, &substream))\n return false;\n \n while (substream.bytes_left)\n {\n if ((size_t)*size + 1 > allocated_size)\n {\n /* Allocate more storage. This tries to guess the\n * number of remaining entries. Round the division\n * upwards. */\n allocated_size += (substream.bytes_left - 1) / field->data_size + 1;\n \n if (!allocate_field(&substream, field->pField, field->data_size, allocated_size))\n {\n status = false;\n break;\n }\n }", " /* Decode the array entry */\n field->pData = *(char**)field->pField + field->data_size * (*size);\n initialize_pointer_field(field->pData, field);\n if (!decode_basic_field(&substream, field))\n {\n status = false;\n break;\n }\n \n if (*size == PB_SIZE_MAX)\n {\n#ifndef PB_NO_ERRMSG\n stream->errmsg = \"too many array entries\";\n#endif\n status = false;\n break;\n }\n \n (*size)++;\n }\n if (!pb_close_string_substream(stream, &substream))\n return false;\n \n return status;\n }\n else\n {\n /* Normal repeated field, i.e. only one item at a time. */\n pb_size_t *size = (pb_size_t*)field->pSize;", " if (*size == PB_SIZE_MAX)\n PB_RETURN_ERROR(stream, \"too many array entries\");\n \n if (!check_wire_type(wire_type, field))\n PB_RETURN_ERROR(stream, \"wrong wire type\");\n", " if (!allocate_field(stream, field->pField, field->data_size, (size_t)(*size + 1)))", " return false;\n ", " field->pData = *(char**)field->pField + field->data_size * (*size);\n (*size)++;", " initialize_pointer_field(field->pData, field);\n return decode_basic_field(stream, field);\n }", " default:\n PB_RETURN_ERROR(stream, \"invalid field type\");\n }\n#endif\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 4292, "char_start": 4283, "chars": "(size_t)(" }, { "char_end": 4302, "char_start": 4297, "chars": " + 1)" }, { "char_end": 4440, "char_start": 4433, "chars": ");\n " }, { "char_end": 4443, "char_start": 4441, "chars": " " }, { "char_end": 4458, "char_start": 4444, "chars": " (*size" }, { "char_end": 4461, "char_start": 4459, "chars": "++" } ], "deleted": [ { "char_end": 4249, "char_start": 4222, "chars": "(*size)++;\n " }, { "char_end": 4448, "char_start": 4447, "chars": "-" }, { "char_end": 4450, "char_start": 4449, "chars": "1" } ] }, "commit_link": "github.com/nanopb/nanopb/commit/45582f1f97f49e2abfdba1463d1e1027682d9856", "file_name": "pb_decode.c", "func_name": "decode_pointer_field", "line_changes": { "added": [ { "char_end": 4305, "char_start": 4206, "line": " if (!allocate_field(stream, field->pField, field->data_size, (size_t)(*size + 1)))\n", "line_no": 110 }, { "char_end": 4436, "char_start": 4352, "line": " field->pData = *(char**)field->pField + field->data_size * (*size);\n", "line_no": 113 }, { "char_end": 4463, "char_start": 4436, "line": " (*size)++;\n", "line_no": 114 } ], "deleted": [ { "char_end": 4233, "char_start": 4206, "line": " (*size)++;\n", "line_no": 110 }, { "char_end": 4318, "char_start": 4233, "line": " if (!allocate_field(stream, field->pField, field->data_size, *size))\n", "line_no": 111 }, { "char_end": 4453, "char_start": 4365, "line": " field->pData = *(char**)field->pField + field->data_size * (*size - 1);\n", "line_no": 114 } ] }, "vul_type": "cwe-125" }
466
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)\n{\n UINT8* ptr;\n int framesize;\n int c, chunks, advance;\n int l, lines;\n int i, j, x = 0, y, ymax;", " /* If not even the chunk size is present, we'd better leave */", " if (bytes < 4)\n\treturn 0;", " /* We don't decode anything unless we have a full chunk in the", " input buffer (on the other hand, the Python part of the driver\n makes sure this is always the case) */", "\n ptr = buf;", " framesize = I32(ptr);\n if (framesize < I32(ptr))\n\treturn 0;", " /* Make sure this is a frame chunk. The Python driver takes\n case of other chunk types. */\n", "", " if (I16(ptr+4) != 0xF1FA) {\n\tstate->errcode = IMAGING_CODEC_UNKNOWN;\n\treturn -1;\n }", " chunks = I16(ptr+6);\n ptr += 16;\n bytes -= 16;", " /* Process subchunks */\n for (c = 0; c < chunks; c++) {\n\tUINT8* data;\n\tif (bytes < 10) {\n\t state->errcode = IMAGING_CODEC_OVERRUN;\n\t return -1;\n\t}\n\tdata = ptr + 6;\n\tswitch (I16(ptr+4)) {\n\tcase 4: case 11:\n\t /* FLI COLOR chunk */\n\t break; /* ignored; handled by Python code */\n\tcase 7:\n\t /* FLI SS2 chunk (word delta) */\n\t lines = I16(data); data += 2;\n\t for (l = y = 0; l < lines && y < state->ysize; l++, y++) {\n\t\tUINT8* buf = (UINT8*) im->image[y];\n\t\tint p, packets;\n\t\tpackets = I16(data); data += 2;\n\t\twhile (packets & 0x8000) {\n\t\t /* flag word */\n\t\t if (packets & 0x4000) {\n\t\t\ty += 65536 - packets; /* skip lines */\n\t\t\tif (y >= state->ysize) {\n\t\t\t state->errcode = IMAGING_CODEC_OVERRUN;\n\t\t\t return -1;\n\t\t\t}\n\t\t\tbuf = (UINT8*) im->image[y];\n\t\t } else {\n\t\t\t/* store last byte (used if line width is odd) */\n\t\t\tbuf[state->xsize-1] = (UINT8) packets;\n\t\t }\n\t\t packets = I16(data); data += 2;\n\t\t}\n\t\tfor (p = x = 0; p < packets; p++) {\n\t\t x += data[0]; /* pixel skip */\n\t\t if (data[1] >= 128) {\n\t\t\ti = 256-data[1]; /* run */\n\t\t\tif (x + i + i > state->xsize)\n\t\t\t break;\n\t\t\tfor (j = 0; j < i; j++) {\n\t\t\t buf[x++] = data[2];\n\t\t\t buf[x++] = data[3];\n\t\t\t}\n\t\t\tdata += 2 + 2;\n\t\t } else {\n\t\t\ti = 2 * (int) data[1]; /* chunk */\n\t\t\tif (x + i > state->xsize)\n\t\t\t break;\n\t\t\tmemcpy(buf + x, data + 2, i);\n\t\t\tdata += 2 + i;\n\t\t\tx += i;\n\t\t }\n\t\t}\n\t\tif (p < packets)\n\t\t break; /* didn't process all packets */\n\t }\n\t if (l < lines) {\n\t\t/* didn't process all lines */\n\t\tstate->errcode = IMAGING_CODEC_OVERRUN;\n\t\treturn -1;\n\t }\n\t break;\n\tcase 12:\n\t /* FLI LC chunk (byte delta) */\n\t y = I16(data); ymax = y + I16(data+2); data += 4;\n\t for (; y < ymax && y < state->ysize; y++) {\n\t\tUINT8* out = (UINT8*) im->image[y];\n\t\tint p, packets = *data++;\n\t\tfor (p = x = 0; p < packets; p++, x += i) {\n\t\t x += data[0]; /* skip pixels */\n\t\t if (data[1] & 0x80) {\n\t\t\ti = 256-data[1]; /* run */\n\t\t\tif (x + i > state->xsize)\n\t\t\t break;\n\t\t\tmemset(out + x, data[2], i);\n\t\t\tdata += 3;\n\t\t } else {\n\t\t\ti = data[1]; /* chunk */\n\t\t\tif (x + i > state->xsize)\n\t\t\t break;\n\t\t\tmemcpy(out + x, data + 2, i);\n\t\t\tdata += i + 2;\n\t\t }\n\t\t}\n\t\tif (p < packets)\n\t\t break; /* didn't process all packets */\n\t }\n\t if (y < ymax) {\n\t\t/* didn't process all lines */\n\t\tstate->errcode = IMAGING_CODEC_OVERRUN;\n\t\treturn -1;\n\t }\n\t break;\n\tcase 13:\n\t /* FLI BLACK chunk */\n\t for (y = 0; y < state->ysize; y++)\n\t\tmemset(im->image[y], 0, state->xsize);\n\t break;\n\tcase 15:\n\t /* FLI BRUN chunk */\n\t for (y = 0; y < state->ysize; y++) {\n\t\tUINT8* out = (UINT8*) im->image[y];\n\t\tdata += 1; /* ignore packetcount byte */\n\t\tfor (x = 0; x < state->xsize; x += i) {\n\t\t if (data[0] & 0x80) {\n\t\t\ti = 256 - data[0];\n\t\t\tif (x + i > state->xsize)\n\t\t\t break; /* safety first */\n\t\t\tmemcpy(out + x, data + 1, i);\n\t\t\tdata += i + 1;\n\t\t } else {\n\t\t\ti = data[0];\n\t\t\tif (x + i > state->xsize)\n\t\t\t break; /* safety first */\n\t\t\tmemset(out + x, data[1], i);\n\t\t\tdata += 2;\n\t\t }\n\t\t}\n\t\tif (x != state->xsize) {\n\t\t /* didn't unpack whole line */\n\t\t state->errcode = IMAGING_CODEC_OVERRUN;\n\t\t return -1;\n\t\t}\n\t }\n\t break;\n\tcase 16:\n\t /* COPY chunk */\n\t for (y = 0; y < state->ysize; y++) {\n\t\tUINT8* buf = (UINT8*) im->image[y];\n\t\tmemcpy(buf, data, state->xsize);\n\t\tdata += state->xsize;\n\t }\n\t break;\n\tcase 18:\n\t /* PSTAMP chunk */\n\t break; /* ignored */\n\tdefault:\n\t /* unknown chunk */\n\t /* printf(\"unknown FLI/FLC chunk: %d\\n\", I16(ptr+4)); */\n\t state->errcode = IMAGING_CODEC_UNKNOWN;\n\t return -1;\n\t}\n\tadvance = I32(ptr);\n\tptr += advance;\n\tbytes -= advance;\n }", " return -1; /* end of frame */\n}" ]
[ 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 668, "char_start": 574, "chars": "\n if (bytes < 8) {\n state->errcode = IMAGING_CODEC_OVERRUN;\n return -1;\n }" } ], "deleted": [ { "char_end": 477, "char_start": 384, "chars": "(on the other hand, the Python part of the driver\n makes sure this is always the case) " } ] }, "commit_link": "github.com/python-pillow/Pillow/commit/a09acd0decd8a87ccce939d5ff65dab59e7d365b", "file_name": "src/libImaging/FliDecode.c", "func_name": "ImagingFliDecode", "line_changes": { "added": [ { "char_end": 387, "char_start": 364, "line": " input buffer */\n", "line_no": 15 }, { "char_end": 596, "char_start": 575, "line": " if (bytes < 8) {\n", "line_no": 26 }, { "char_end": 644, "char_start": 596, "line": " state->errcode = IMAGING_CODEC_OVERRUN;\n", "line_no": 27 }, { "char_end": 663, "char_start": 644, "line": " return -1;\n", "line_no": 28 }, { "char_end": 669, "char_start": 663, "line": " }\n", "line_no": 29 } ], "deleted": [ { "char_end": 434, "char_start": 364, "line": " input buffer (on the other hand, the Python part of the driver\n", "line_no": 15 }, { "char_end": 480, "char_start": 434, "line": " makes sure this is always the case) */\n", "line_no": 16 } ] }, "vul_type": "cwe-125" }
467
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)\n{\n UINT8* ptr;\n int framesize;\n int c, chunks, advance;\n int l, lines;\n int i, j, x = 0, y, ymax;", " /* If not even the chunk size is present, we'd better leave */", " if (bytes < 4)\n\treturn 0;", " /* We don't decode anything unless we have a full chunk in the", " input buffer */", "\n ptr = buf;", " framesize = I32(ptr);\n if (framesize < I32(ptr))\n\treturn 0;", " /* Make sure this is a frame chunk. The Python driver takes\n case of other chunk types. */\n", " if (bytes < 8) {\n state->errcode = IMAGING_CODEC_OVERRUN;\n return -1;\n }", " if (I16(ptr+4) != 0xF1FA) {\n\tstate->errcode = IMAGING_CODEC_UNKNOWN;\n\treturn -1;\n }", " chunks = I16(ptr+6);\n ptr += 16;\n bytes -= 16;", " /* Process subchunks */\n for (c = 0; c < chunks; c++) {\n\tUINT8* data;\n\tif (bytes < 10) {\n\t state->errcode = IMAGING_CODEC_OVERRUN;\n\t return -1;\n\t}\n\tdata = ptr + 6;\n\tswitch (I16(ptr+4)) {\n\tcase 4: case 11:\n\t /* FLI COLOR chunk */\n\t break; /* ignored; handled by Python code */\n\tcase 7:\n\t /* FLI SS2 chunk (word delta) */\n\t lines = I16(data); data += 2;\n\t for (l = y = 0; l < lines && y < state->ysize; l++, y++) {\n\t\tUINT8* buf = (UINT8*) im->image[y];\n\t\tint p, packets;\n\t\tpackets = I16(data); data += 2;\n\t\twhile (packets & 0x8000) {\n\t\t /* flag word */\n\t\t if (packets & 0x4000) {\n\t\t\ty += 65536 - packets; /* skip lines */\n\t\t\tif (y >= state->ysize) {\n\t\t\t state->errcode = IMAGING_CODEC_OVERRUN;\n\t\t\t return -1;\n\t\t\t}\n\t\t\tbuf = (UINT8*) im->image[y];\n\t\t } else {\n\t\t\t/* store last byte (used if line width is odd) */\n\t\t\tbuf[state->xsize-1] = (UINT8) packets;\n\t\t }\n\t\t packets = I16(data); data += 2;\n\t\t}\n\t\tfor (p = x = 0; p < packets; p++) {\n\t\t x += data[0]; /* pixel skip */\n\t\t if (data[1] >= 128) {\n\t\t\ti = 256-data[1]; /* run */\n\t\t\tif (x + i + i > state->xsize)\n\t\t\t break;\n\t\t\tfor (j = 0; j < i; j++) {\n\t\t\t buf[x++] = data[2];\n\t\t\t buf[x++] = data[3];\n\t\t\t}\n\t\t\tdata += 2 + 2;\n\t\t } else {\n\t\t\ti = 2 * (int) data[1]; /* chunk */\n\t\t\tif (x + i > state->xsize)\n\t\t\t break;\n\t\t\tmemcpy(buf + x, data + 2, i);\n\t\t\tdata += 2 + i;\n\t\t\tx += i;\n\t\t }\n\t\t}\n\t\tif (p < packets)\n\t\t break; /* didn't process all packets */\n\t }\n\t if (l < lines) {\n\t\t/* didn't process all lines */\n\t\tstate->errcode = IMAGING_CODEC_OVERRUN;\n\t\treturn -1;\n\t }\n\t break;\n\tcase 12:\n\t /* FLI LC chunk (byte delta) */\n\t y = I16(data); ymax = y + I16(data+2); data += 4;\n\t for (; y < ymax && y < state->ysize; y++) {\n\t\tUINT8* out = (UINT8*) im->image[y];\n\t\tint p, packets = *data++;\n\t\tfor (p = x = 0; p < packets; p++, x += i) {\n\t\t x += data[0]; /* skip pixels */\n\t\t if (data[1] & 0x80) {\n\t\t\ti = 256-data[1]; /* run */\n\t\t\tif (x + i > state->xsize)\n\t\t\t break;\n\t\t\tmemset(out + x, data[2], i);\n\t\t\tdata += 3;\n\t\t } else {\n\t\t\ti = data[1]; /* chunk */\n\t\t\tif (x + i > state->xsize)\n\t\t\t break;\n\t\t\tmemcpy(out + x, data + 2, i);\n\t\t\tdata += i + 2;\n\t\t }\n\t\t}\n\t\tif (p < packets)\n\t\t break; /* didn't process all packets */\n\t }\n\t if (y < ymax) {\n\t\t/* didn't process all lines */\n\t\tstate->errcode = IMAGING_CODEC_OVERRUN;\n\t\treturn -1;\n\t }\n\t break;\n\tcase 13:\n\t /* FLI BLACK chunk */\n\t for (y = 0; y < state->ysize; y++)\n\t\tmemset(im->image[y], 0, state->xsize);\n\t break;\n\tcase 15:\n\t /* FLI BRUN chunk */\n\t for (y = 0; y < state->ysize; y++) {\n\t\tUINT8* out = (UINT8*) im->image[y];\n\t\tdata += 1; /* ignore packetcount byte */\n\t\tfor (x = 0; x < state->xsize; x += i) {\n\t\t if (data[0] & 0x80) {\n\t\t\ti = 256 - data[0];\n\t\t\tif (x + i > state->xsize)\n\t\t\t break; /* safety first */\n\t\t\tmemcpy(out + x, data + 1, i);\n\t\t\tdata += i + 1;\n\t\t } else {\n\t\t\ti = data[0];\n\t\t\tif (x + i > state->xsize)\n\t\t\t break; /* safety first */\n\t\t\tmemset(out + x, data[1], i);\n\t\t\tdata += 2;\n\t\t }\n\t\t}\n\t\tif (x != state->xsize) {\n\t\t /* didn't unpack whole line */\n\t\t state->errcode = IMAGING_CODEC_OVERRUN;\n\t\t return -1;\n\t\t}\n\t }\n\t break;\n\tcase 16:\n\t /* COPY chunk */\n\t for (y = 0; y < state->ysize; y++) {\n\t\tUINT8* buf = (UINT8*) im->image[y];\n\t\tmemcpy(buf, data, state->xsize);\n\t\tdata += state->xsize;\n\t }\n\t break;\n\tcase 18:\n\t /* PSTAMP chunk */\n\t break; /* ignored */\n\tdefault:\n\t /* unknown chunk */\n\t /* printf(\"unknown FLI/FLC chunk: %d\\n\", I16(ptr+4)); */\n\t state->errcode = IMAGING_CODEC_UNKNOWN;\n\t return -1;\n\t}\n\tadvance = I32(ptr);\n\tptr += advance;\n\tbytes -= advance;\n }", " return -1; /* end of frame */\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 668, "char_start": 574, "chars": "\n if (bytes < 8) {\n state->errcode = IMAGING_CODEC_OVERRUN;\n return -1;\n }" } ], "deleted": [ { "char_end": 477, "char_start": 384, "chars": "(on the other hand, the Python part of the driver\n makes sure this is always the case) " } ] }, "commit_link": "github.com/python-pillow/Pillow/commit/a09acd0decd8a87ccce939d5ff65dab59e7d365b", "file_name": "src/libImaging/FliDecode.c", "func_name": "ImagingFliDecode", "line_changes": { "added": [ { "char_end": 387, "char_start": 364, "line": " input buffer */\n", "line_no": 15 }, { "char_end": 596, "char_start": 575, "line": " if (bytes < 8) {\n", "line_no": 26 }, { "char_end": 644, "char_start": 596, "line": " state->errcode = IMAGING_CODEC_OVERRUN;\n", "line_no": 27 }, { "char_end": 663, "char_start": 644, "line": " return -1;\n", "line_no": 28 }, { "char_end": 669, "char_start": 663, "line": " }\n", "line_no": 29 } ], "deleted": [ { "char_end": 434, "char_start": 364, "line": " input buffer (on the other hand, the Python part of the driver\n", "line_no": 15 }, { "char_end": 480, "char_start": 434, "line": " makes sure this is always the case) */\n", "line_no": 16 } ] }, "vul_type": "cwe-125" }
467
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg,\n\tvoid *buf, int peekonly)\n{\n\tstruct tmComResBusInfo *bus = &dev->bus;\n\tu32 bytes_to_read, write_distance, curr_grp, curr_gwp,\n\t\tnew_grp, buf_size, space_rem;\n\tstruct tmComResInfo msg_tmp;\n\tint ret = SAA_ERR_BAD_PARAMETER;", "\tsaa7164_bus_verify(dev);", "\tif (msg == NULL)\n\t\treturn ret;", "\tif (msg->size > dev->bus.m_wMaxReqSize) {\n\t\tprintk(KERN_ERR \"%s() Exceeded dev->bus.m_wMaxReqSize\\n\",\n\t\t\t__func__);\n\t\treturn ret;\n\t}", "\tif ((peekonly == 0) && (msg->size > 0) && (buf == NULL)) {\n\t\tprintk(KERN_ERR\n\t\t\t\"%s() Missing msg buf, size should be %d bytes\\n\",\n\t\t\t__func__, msg->size);\n\t\treturn ret;\n\t}", "\tmutex_lock(&bus->lock);", "\t/* Peek the bus to see if a msg exists, if it's not what we're expecting\n\t * then return cleanly else read the message from the bus.\n\t */\n\tcurr_gwp = saa7164_readl(bus->m_dwGetWritePos);\n\tcurr_grp = saa7164_readl(bus->m_dwGetReadPos);", "\tif (curr_gwp == curr_grp) {\n\t\tret = SAA_ERR_EMPTY;\n\t\tgoto out;\n\t}", "\tbytes_to_read = sizeof(*msg);", "\t/* Calculate write distance to current read position */\n\twrite_distance = 0;\n\tif (curr_gwp >= curr_grp)\n\t\t/* Write doesn't wrap around the ring */\n\t\twrite_distance = curr_gwp - curr_grp;\n\telse\n\t\t/* Write wraps around the ring */\n\t\twrite_distance = curr_gwp + bus->m_dwSizeGetRing - curr_grp;", "\tif (bytes_to_read > write_distance) {\n\t\tprintk(KERN_ERR \"%s() No message/response found\\n\", __func__);\n\t\tret = SAA_ERR_INVALID_COMMAND;\n\t\tgoto out;\n\t}", "\t/* Calculate the new read position */\n\tnew_grp = curr_grp + bytes_to_read;\n\tif (new_grp > bus->m_dwSizeGetRing) {", "\t\t/* Ring wraps */\n\t\tnew_grp -= bus->m_dwSizeGetRing;\n\t\tspace_rem = bus->m_dwSizeGetRing - curr_grp;", "\t\tmemcpy_fromio(&msg_tmp, bus->m_pdwGetRing + curr_grp, space_rem);\n\t\tmemcpy_fromio((u8 *)&msg_tmp + space_rem, bus->m_pdwGetRing,\n\t\t\tbytes_to_read - space_rem);", "\t} else {\n\t\t/* No wrapping */\n\t\tmemcpy_fromio(&msg_tmp, bus->m_pdwGetRing + curr_grp, bytes_to_read);\n\t}\n\t/* Convert from little endian to CPU */\n\tmsg_tmp.size = le16_to_cpu((__force __le16)msg_tmp.size);\n\tmsg_tmp.command = le32_to_cpu((__force __le32)msg_tmp.command);\n\tmsg_tmp.controlselector = le16_to_cpu((__force __le16)msg_tmp.controlselector);", "", "\n\t/* No need to update the read positions, because this was a peek */\n\t/* If the caller specifically want to peek, return */\n\tif (peekonly) {", "\t\tmemcpy(msg, &msg_tmp, sizeof(*msg));", "\t\tgoto peekout;\n\t}", "\t/* Check if the command/response matches what is expected */\n\tif ((msg_tmp.id != msg->id) || (msg_tmp.command != msg->command) ||\n\t\t(msg_tmp.controlselector != msg->controlselector) ||\n\t\t(msg_tmp.seqno != msg->seqno) || (msg_tmp.size != msg->size)) {", "\t\tprintk(KERN_ERR \"%s() Unexpected msg miss-match\\n\", __func__);\n\t\tsaa7164_bus_dumpmsg(dev, msg, buf);\n\t\tsaa7164_bus_dumpmsg(dev, &msg_tmp, NULL);\n\t\tret = SAA_ERR_INVALID_COMMAND;\n\t\tgoto out;\n\t}", "\t/* Get the actual command and response from the bus */\n\tbuf_size = msg->size;", "\tbytes_to_read = sizeof(*msg) + msg->size;\n\t/* Calculate write distance to current read position */\n\twrite_distance = 0;\n\tif (curr_gwp >= curr_grp)\n\t\t/* Write doesn't wrap around the ring */\n\t\twrite_distance = curr_gwp - curr_grp;\n\telse\n\t\t/* Write wraps around the ring */\n\t\twrite_distance = curr_gwp + bus->m_dwSizeGetRing - curr_grp;", "\tif (bytes_to_read > write_distance) {\n\t\tprintk(KERN_ERR \"%s() Invalid bus state, missing msg or mangled ring, faulty H/W / bad code?\\n\",\n\t\t __func__);\n\t\tret = SAA_ERR_INVALID_COMMAND;\n\t\tgoto out;\n\t}", "\t/* Calculate the new read position */\n\tnew_grp = curr_grp + bytes_to_read;\n\tif (new_grp > bus->m_dwSizeGetRing) {", "\t\t/* Ring wraps */\n\t\tnew_grp -= bus->m_dwSizeGetRing;\n\t\tspace_rem = bus->m_dwSizeGetRing - curr_grp;", "\t\tif (space_rem < sizeof(*msg)) {", "\t\t\t/* msg wraps around the ring */\n\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, space_rem);\n\t\t\tmemcpy_fromio((u8 *)msg + space_rem, bus->m_pdwGetRing,\n\t\t\t\tsizeof(*msg) - space_rem);", "\t\t\tif (buf)\n\t\t\t\tmemcpy_fromio(buf, bus->m_pdwGetRing + sizeof(*msg) -\n\t\t\t\t\tspace_rem, buf_size);", "\t\t} else if (space_rem == sizeof(*msg)) {", "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));", "\t\t\tif (buf)\n\t\t\t\tmemcpy_fromio(buf, bus->m_pdwGetRing, buf_size);\n\t\t} else {\n\t\t\t/* Additional data wraps around the ring */", "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));", "\t\t\tif (buf) {\n\t\t\t\tmemcpy_fromio(buf, bus->m_pdwGetRing + curr_grp +\n\t\t\t\t\tsizeof(*msg), space_rem - sizeof(*msg));\n\t\t\t\tmemcpy_fromio(buf + space_rem - sizeof(*msg),\n\t\t\t\t\tbus->m_pdwGetRing, bytes_to_read -\n\t\t\t\t\tspace_rem);\n\t\t\t}", "\t\t}", "\t} else {\n\t\t/* No wrapping */", "\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));", "\t\tif (buf)\n\t\t\tmemcpy_fromio(buf, bus->m_pdwGetRing + curr_grp + sizeof(*msg),\n\t\t\t\tbuf_size);\n\t}", "\t/* Convert from little endian to CPU */\n\tmsg->size = le16_to_cpu((__force __le16)msg->size);\n\tmsg->command = le32_to_cpu((__force __le32)msg->command);\n\tmsg->controlselector = le16_to_cpu((__force __le16)msg->controlselector);", "\n\t/* Update the read positions, adjusting the ring */\n\tsaa7164_writel(bus->m_dwGetReadPos, new_grp);", "peekout:\n\tret = SAA_OK;\nout:\n\tmutex_unlock(&bus->lock);\n\tsaa7164_bus_verify(dev);\n\treturn ret;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 2244, "char_start": 2206, "chars": "\tmemcpy(msg, &msg_tmp, sizeof(*msg));\n" }, { "char_end": 4349, "char_start": 4349, "chars": "" } ], "deleted": [ { "char_end": 2387, "char_start": 2348, "chars": "\t\tmemcpy(msg, &msg_tmp, sizeof(*msg));\n" }, { "char_end": 3921, "char_start": 3732, "chars": "\t\t\t/* msg wraps around the ring */\n\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, space_rem);\n\t\t\tmemcpy_fromio((u8 *)msg + space_rem, bus->m_pdwGetRing,\n\t\t\t\tsizeof(*msg) - space_rem);\n" }, { "char_end": 4128, "char_start": 4061, "chars": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n" }, { "char_end": 4318, "char_start": 4251, "chars": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n" }, { "char_end": 4646, "char_start": 4580, "chars": "\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n" }, { "char_end": 4969, "char_start": 4741, "chars": "\n\t/* Convert from little endian to CPU */\n\tmsg->size = le16_to_cpu((__force __le16)msg->size);\n\tmsg->command = le32_to_cpu((__force __le32)msg->command);\n\tmsg->controlselector = le16_to_cpu((__force __le16)msg->controlselector);" } ] }, "commit_link": "github.com/stoth68000/media-tree/commit/354dd3924a2e43806774953de536257548b5002c", "file_name": "drivers/media/pci/saa7164/saa7164-bus.c", "func_name": "saa7164_bus_get", "line_changes": { "added": [ { "char_end": 2244, "char_start": 2206, "line": "\tmemcpy(msg, &msg_tmp, sizeof(*msg));\n", "line_no": 78 } ], "deleted": [ { "char_end": 2387, "char_start": 2348, "line": "\t\tmemcpy(msg, &msg_tmp, sizeof(*msg));\n", "line_no": 82 }, { "char_end": 3767, "char_start": 3732, "line": "\t\t\t/* msg wraps around the ring */\n", "line_no": 127 }, { "char_end": 3831, "char_start": 3767, "line": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, space_rem);\n", "line_no": 128 }, { "char_end": 3890, "char_start": 3831, "line": "\t\t\tmemcpy_fromio((u8 *)msg + space_rem, bus->m_pdwGetRing,\n", "line_no": 129 }, { "char_end": 3921, "char_start": 3890, "line": "\t\t\t\tsizeof(*msg) - space_rem);\n", "line_no": 130 }, { "char_end": 4128, "char_start": 4061, "line": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n", "line_no": 136 }, { "char_end": 4318, "char_start": 4251, "line": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n", "line_no": 141 }, { "char_end": 4646, "char_start": 4580, "line": "\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n", "line_no": 154 }, { "char_end": 4783, "char_start": 4742, "line": "\t/* Convert from little endian to CPU */\n", "line_no": 159 }, { "char_end": 4836, "char_start": 4783, "line": "\tmsg->size = le16_to_cpu((__force __le16)msg->size);\n", "line_no": 160 }, { "char_end": 4895, "char_start": 4836, "line": "\tmsg->command = le32_to_cpu((__force __le32)msg->command);\n", "line_no": 161 }, { "char_end": 4970, "char_start": 4895, "line": "\tmsg->controlselector = le16_to_cpu((__force __le16)msg->controlselector);\n", "line_no": 162 } ] }, "vul_type": "cwe-125" }
468
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg,\n\tvoid *buf, int peekonly)\n{\n\tstruct tmComResBusInfo *bus = &dev->bus;\n\tu32 bytes_to_read, write_distance, curr_grp, curr_gwp,\n\t\tnew_grp, buf_size, space_rem;\n\tstruct tmComResInfo msg_tmp;\n\tint ret = SAA_ERR_BAD_PARAMETER;", "\tsaa7164_bus_verify(dev);", "\tif (msg == NULL)\n\t\treturn ret;", "\tif (msg->size > dev->bus.m_wMaxReqSize) {\n\t\tprintk(KERN_ERR \"%s() Exceeded dev->bus.m_wMaxReqSize\\n\",\n\t\t\t__func__);\n\t\treturn ret;\n\t}", "\tif ((peekonly == 0) && (msg->size > 0) && (buf == NULL)) {\n\t\tprintk(KERN_ERR\n\t\t\t\"%s() Missing msg buf, size should be %d bytes\\n\",\n\t\t\t__func__, msg->size);\n\t\treturn ret;\n\t}", "\tmutex_lock(&bus->lock);", "\t/* Peek the bus to see if a msg exists, if it's not what we're expecting\n\t * then return cleanly else read the message from the bus.\n\t */\n\tcurr_gwp = saa7164_readl(bus->m_dwGetWritePos);\n\tcurr_grp = saa7164_readl(bus->m_dwGetReadPos);", "\tif (curr_gwp == curr_grp) {\n\t\tret = SAA_ERR_EMPTY;\n\t\tgoto out;\n\t}", "\tbytes_to_read = sizeof(*msg);", "\t/* Calculate write distance to current read position */\n\twrite_distance = 0;\n\tif (curr_gwp >= curr_grp)\n\t\t/* Write doesn't wrap around the ring */\n\t\twrite_distance = curr_gwp - curr_grp;\n\telse\n\t\t/* Write wraps around the ring */\n\t\twrite_distance = curr_gwp + bus->m_dwSizeGetRing - curr_grp;", "\tif (bytes_to_read > write_distance) {\n\t\tprintk(KERN_ERR \"%s() No message/response found\\n\", __func__);\n\t\tret = SAA_ERR_INVALID_COMMAND;\n\t\tgoto out;\n\t}", "\t/* Calculate the new read position */\n\tnew_grp = curr_grp + bytes_to_read;\n\tif (new_grp > bus->m_dwSizeGetRing) {", "\t\t/* Ring wraps */\n\t\tnew_grp -= bus->m_dwSizeGetRing;\n\t\tspace_rem = bus->m_dwSizeGetRing - curr_grp;", "\t\tmemcpy_fromio(&msg_tmp, bus->m_pdwGetRing + curr_grp, space_rem);\n\t\tmemcpy_fromio((u8 *)&msg_tmp + space_rem, bus->m_pdwGetRing,\n\t\t\tbytes_to_read - space_rem);", "\t} else {\n\t\t/* No wrapping */\n\t\tmemcpy_fromio(&msg_tmp, bus->m_pdwGetRing + curr_grp, bytes_to_read);\n\t}\n\t/* Convert from little endian to CPU */\n\tmsg_tmp.size = le16_to_cpu((__force __le16)msg_tmp.size);\n\tmsg_tmp.command = le32_to_cpu((__force __le32)msg_tmp.command);\n\tmsg_tmp.controlselector = le16_to_cpu((__force __le16)msg_tmp.controlselector);", "\tmemcpy(msg, &msg_tmp, sizeof(*msg));", "\n\t/* No need to update the read positions, because this was a peek */\n\t/* If the caller specifically want to peek, return */\n\tif (peekonly) {", "", "\t\tgoto peekout;\n\t}", "\t/* Check if the command/response matches what is expected */\n\tif ((msg_tmp.id != msg->id) || (msg_tmp.command != msg->command) ||\n\t\t(msg_tmp.controlselector != msg->controlselector) ||\n\t\t(msg_tmp.seqno != msg->seqno) || (msg_tmp.size != msg->size)) {", "\t\tprintk(KERN_ERR \"%s() Unexpected msg miss-match\\n\", __func__);\n\t\tsaa7164_bus_dumpmsg(dev, msg, buf);\n\t\tsaa7164_bus_dumpmsg(dev, &msg_tmp, NULL);\n\t\tret = SAA_ERR_INVALID_COMMAND;\n\t\tgoto out;\n\t}", "\t/* Get the actual command and response from the bus */\n\tbuf_size = msg->size;", "\tbytes_to_read = sizeof(*msg) + msg->size;\n\t/* Calculate write distance to current read position */\n\twrite_distance = 0;\n\tif (curr_gwp >= curr_grp)\n\t\t/* Write doesn't wrap around the ring */\n\t\twrite_distance = curr_gwp - curr_grp;\n\telse\n\t\t/* Write wraps around the ring */\n\t\twrite_distance = curr_gwp + bus->m_dwSizeGetRing - curr_grp;", "\tif (bytes_to_read > write_distance) {\n\t\tprintk(KERN_ERR \"%s() Invalid bus state, missing msg or mangled ring, faulty H/W / bad code?\\n\",\n\t\t __func__);\n\t\tret = SAA_ERR_INVALID_COMMAND;\n\t\tgoto out;\n\t}", "\t/* Calculate the new read position */\n\tnew_grp = curr_grp + bytes_to_read;\n\tif (new_grp > bus->m_dwSizeGetRing) {", "\t\t/* Ring wraps */\n\t\tnew_grp -= bus->m_dwSizeGetRing;\n\t\tspace_rem = bus->m_dwSizeGetRing - curr_grp;", "\t\tif (space_rem < sizeof(*msg)) {", "", "\t\t\tif (buf)\n\t\t\t\tmemcpy_fromio(buf, bus->m_pdwGetRing + sizeof(*msg) -\n\t\t\t\t\tspace_rem, buf_size);", "\t\t} else if (space_rem == sizeof(*msg)) {", "", "\t\t\tif (buf)\n\t\t\t\tmemcpy_fromio(buf, bus->m_pdwGetRing, buf_size);\n\t\t} else {\n\t\t\t/* Additional data wraps around the ring */", "", "\t\t\tif (buf) {\n\t\t\t\tmemcpy_fromio(buf, bus->m_pdwGetRing + curr_grp +\n\t\t\t\t\tsizeof(*msg), space_rem - sizeof(*msg));\n\t\t\t\tmemcpy_fromio(buf + space_rem - sizeof(*msg),\n\t\t\t\t\tbus->m_pdwGetRing, bytes_to_read -\n\t\t\t\t\tspace_rem);\n\t\t\t}", "\t\t}", "\t} else {\n\t\t/* No wrapping */", "", "\t\tif (buf)\n\t\t\tmemcpy_fromio(buf, bus->m_pdwGetRing + curr_grp + sizeof(*msg),\n\t\t\t\tbuf_size);\n\t}", "", "\n\t/* Update the read positions, adjusting the ring */\n\tsaa7164_writel(bus->m_dwGetReadPos, new_grp);", "peekout:\n\tret = SAA_OK;\nout:\n\tmutex_unlock(&bus->lock);\n\tsaa7164_bus_verify(dev);\n\treturn ret;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 2244, "char_start": 2206, "chars": "\tmemcpy(msg, &msg_tmp, sizeof(*msg));\n" }, { "char_end": 4349, "char_start": 4349, "chars": "" } ], "deleted": [ { "char_end": 2387, "char_start": 2348, "chars": "\t\tmemcpy(msg, &msg_tmp, sizeof(*msg));\n" }, { "char_end": 3921, "char_start": 3732, "chars": "\t\t\t/* msg wraps around the ring */\n\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, space_rem);\n\t\t\tmemcpy_fromio((u8 *)msg + space_rem, bus->m_pdwGetRing,\n\t\t\t\tsizeof(*msg) - space_rem);\n" }, { "char_end": 4128, "char_start": 4061, "chars": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n" }, { "char_end": 4318, "char_start": 4251, "chars": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n" }, { "char_end": 4646, "char_start": 4580, "chars": "\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n" }, { "char_end": 4969, "char_start": 4741, "chars": "\n\t/* Convert from little endian to CPU */\n\tmsg->size = le16_to_cpu((__force __le16)msg->size);\n\tmsg->command = le32_to_cpu((__force __le32)msg->command);\n\tmsg->controlselector = le16_to_cpu((__force __le16)msg->controlselector);" } ] }, "commit_link": "github.com/stoth68000/media-tree/commit/354dd3924a2e43806774953de536257548b5002c", "file_name": "drivers/media/pci/saa7164/saa7164-bus.c", "func_name": "saa7164_bus_get", "line_changes": { "added": [ { "char_end": 2244, "char_start": 2206, "line": "\tmemcpy(msg, &msg_tmp, sizeof(*msg));\n", "line_no": 78 } ], "deleted": [ { "char_end": 2387, "char_start": 2348, "line": "\t\tmemcpy(msg, &msg_tmp, sizeof(*msg));\n", "line_no": 82 }, { "char_end": 3767, "char_start": 3732, "line": "\t\t\t/* msg wraps around the ring */\n", "line_no": 127 }, { "char_end": 3831, "char_start": 3767, "line": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, space_rem);\n", "line_no": 128 }, { "char_end": 3890, "char_start": 3831, "line": "\t\t\tmemcpy_fromio((u8 *)msg + space_rem, bus->m_pdwGetRing,\n", "line_no": 129 }, { "char_end": 3921, "char_start": 3890, "line": "\t\t\t\tsizeof(*msg) - space_rem);\n", "line_no": 130 }, { "char_end": 4128, "char_start": 4061, "line": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n", "line_no": 136 }, { "char_end": 4318, "char_start": 4251, "line": "\t\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n", "line_no": 141 }, { "char_end": 4646, "char_start": 4580, "line": "\t\tmemcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));\n", "line_no": 154 }, { "char_end": 4783, "char_start": 4742, "line": "\t/* Convert from little endian to CPU */\n", "line_no": 159 }, { "char_end": 4836, "char_start": 4783, "line": "\tmsg->size = le16_to_cpu((__force __le16)msg->size);\n", "line_no": 160 }, { "char_end": 4895, "char_start": 4836, "line": "\tmsg->command = le32_to_cpu((__force __le32)msg->command);\n", "line_no": 161 }, { "char_end": 4970, "char_start": 4895, "line": "\tmsg->controlselector = le16_to_cpu((__force __le16)msg->controlselector);\n", "line_no": 162 } ] }, "vul_type": "cwe-125" }
468
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static UINT parallel_process_irp_create(PARALLEL_DEVICE* parallel, IRP* irp)\n{\n\tchar* path = NULL;\n\tint status;", "", "\tUINT32 PathLength;", "\tStream_Seek(irp->input, 28);", "\t/* DesiredAccess(4) AllocationSize(8), FileAttributes(4) */\n\t/* SharedAccess(4) CreateDisposition(4), CreateOptions(4) */", "", "\tStream_Read_UINT32(irp->input, PathLength);", "\tstatus = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*)Stream_Pointer(irp->input), PathLength / 2,\n\t &path, 0, NULL, NULL);", "\n\tif (status < 1)\n\t\tif (!(path = (char*)calloc(1, 1)))\n\t\t{\n\t\t\tWLog_ERR(TAG, \"calloc failed!\");\n\t\t\treturn CHANNEL_RC_NO_MEMORY;\n\t\t}", "\tparallel->id = irp->devman->id_sequence++;\n\tparallel->file = open(parallel->path, O_RDWR);", "\tif (parallel->file < 0)\n\t{\n\t\tirp->IoStatus = STATUS_ACCESS_DENIED;\n\t\tparallel->id = 0;\n\t}\n\telse\n\t{\n\t\t/* all read and write operations should be non-blocking */\n\t\tif (fcntl(parallel->file, F_SETFL, O_NONBLOCK) == -1)\n\t\t{\n\t\t}\n\t}", "\tStream_Write_UINT32(irp->output, parallel->id);\n\tStream_Write_UINT8(irp->output, 0);\n\tfree(path);\n\treturn irp->Complete(irp);\n}" ]
[ 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 126, "char_start": 113, "chars": "WCHAR* ptr;\n\t" }, { "char_end": 151, "char_start": 146, "chars": "if (!" }, { "char_end": 162, "char_start": 158, "chars": "Safe" }, { "char_end": 211, "char_start": 182, "chars": ")\n\t\treturn ERROR_INVALID_DATA" }, { "char_end": 414, "char_start": 337, "chars": "if (Stream_GetRemainingLength(irp->input) < 4)\n\t\treturn ERROR_INVALID_DATA;\n\t" }, { "char_end": 460, "char_start": 459, "chars": "p" }, { "char_end": 462, "char_start": 461, "chars": "r" }, { "char_end": 533, "char_start": 499, "chars": ";\n\tif (!Stream_SafeSeek(irp->input" }, { "char_end": 556, "char_start": 545, "chars": "))\n\t\treturn" }, { "char_end": 576, "char_start": 557, "chars": "ERROR_INVALID_DATA;" }, { "char_end": 584, "char_start": 578, "chars": "status" }, { "char_end": 586, "char_start": 585, "chars": "=" }, { "char_end": 614, "char_start": 587, "chars": "ConvertFromUnicode(CP_UTF8," }, { "char_end": 617, "char_start": 615, "chars": "0," }, { "char_end": 622, "char_start": 618, "chars": "ptr," }, { "char_end": 633, "char_start": 623, "chars": "PathLength" }, { "char_end": 635, "char_start": 634, "chars": "/" }, { "char_end": 638, "char_start": 636, "chars": "2," } ], "deleted": [ { "char_end": 332, "char_start": 331, "chars": "s" }, { "char_end": 345, "char_start": 333, "chars": "atus = Conve" }, { "char_end": 367, "char_start": 346, "chars": "tFromUnicode(CP_UTF8," }, { "char_end": 370, "char_start": 368, "chars": "0," }, { "char_end": 422, "char_start": 417, "chars": " / 2," }, { "char_end": 443, "char_start": 424, "chars": " " } ] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/795842f4096501fcefc1a7f535ccc8132feb31d7", "file_name": "channels/parallel/client/parallel_main.c", "func_name": "parallel_process_irp_create", "line_changes": { "added": [ { "char_end": 125, "char_start": 112, "line": "\tWCHAR* ptr;\n", "line_no": 5 }, { "char_end": 184, "char_start": 145, "line": "\tif (!Stream_SafeSeek(irp->input, 28))\n", "line_no": 7 }, { "char_end": 213, "char_start": 184, "line": "\t\treturn ERROR_INVALID_DATA;\n", "line_no": 8 }, { "char_end": 384, "char_start": 336, "line": "\tif (Stream_GetRemainingLength(irp->input) < 4)\n", "line_no": 11 }, { "char_end": 413, "char_start": 384, "line": "\t\treturn ERROR_INVALID_DATA;\n", "line_no": 12 }, { "char_end": 501, "char_start": 458, "line": "\tptr = (WCHAR*)Stream_Pointer(irp->input);\n", "line_no": 14 }, { "char_end": 548, "char_start": 501, "line": "\tif (!Stream_SafeSeek(irp->input, PathLength))\n", "line_no": 15 }, { "char_end": 577, "char_start": 548, "line": "\t\treturn ERROR_INVALID_DATA;\n", "line_no": 16 }, { "char_end": 662, "char_start": 577, "line": "\tstatus = ConvertFromUnicode(CP_UTF8, 0, ptr, PathLength / 2, &path, 0, NULL, NULL);\n", "line_no": 17 } ], "deleted": [ { "char_end": 162, "char_start": 132, "line": "\tStream_Seek(irp->input, 28);\n", "line_no": 6 }, { "char_end": 423, "char_start": 330, "line": "\tstatus = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*)Stream_Pointer(irp->input), PathLength / 2,\n", "line_no": 10 }, { "char_end": 475, "char_start": 423, "line": "\t &path, 0, NULL, NULL);\n", "line_no": 11 } ] }, "vul_type": "cwe-125" }
469
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static UINT parallel_process_irp_create(PARALLEL_DEVICE* parallel, IRP* irp)\n{\n\tchar* path = NULL;\n\tint status;", "\tWCHAR* ptr;", "\tUINT32 PathLength;", "\tif (!Stream_SafeSeek(irp->input, 28))\n\t\treturn ERROR_INVALID_DATA;", "\t/* DesiredAccess(4) AllocationSize(8), FileAttributes(4) */\n\t/* SharedAccess(4) CreateDisposition(4), CreateOptions(4) */", "\tif (Stream_GetRemainingLength(irp->input) < 4)\n\t\treturn ERROR_INVALID_DATA;", "\tStream_Read_UINT32(irp->input, PathLength);", "\tptr = (WCHAR*)Stream_Pointer(irp->input);\n\tif (!Stream_SafeSeek(irp->input, PathLength))\n\t\treturn ERROR_INVALID_DATA;\n\tstatus = ConvertFromUnicode(CP_UTF8, 0, ptr, PathLength / 2, &path, 0, NULL, NULL);", "\n\tif (status < 1)\n\t\tif (!(path = (char*)calloc(1, 1)))\n\t\t{\n\t\t\tWLog_ERR(TAG, \"calloc failed!\");\n\t\t\treturn CHANNEL_RC_NO_MEMORY;\n\t\t}", "\tparallel->id = irp->devman->id_sequence++;\n\tparallel->file = open(parallel->path, O_RDWR);", "\tif (parallel->file < 0)\n\t{\n\t\tirp->IoStatus = STATUS_ACCESS_DENIED;\n\t\tparallel->id = 0;\n\t}\n\telse\n\t{\n\t\t/* all read and write operations should be non-blocking */\n\t\tif (fcntl(parallel->file, F_SETFL, O_NONBLOCK) == -1)\n\t\t{\n\t\t}\n\t}", "\tStream_Write_UINT32(irp->output, parallel->id);\n\tStream_Write_UINT8(irp->output, 0);\n\tfree(path);\n\treturn irp->Complete(irp);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 126, "char_start": 113, "chars": "WCHAR* ptr;\n\t" }, { "char_end": 151, "char_start": 146, "chars": "if (!" }, { "char_end": 162, "char_start": 158, "chars": "Safe" }, { "char_end": 211, "char_start": 182, "chars": ")\n\t\treturn ERROR_INVALID_DATA" }, { "char_end": 414, "char_start": 337, "chars": "if (Stream_GetRemainingLength(irp->input) < 4)\n\t\treturn ERROR_INVALID_DATA;\n\t" }, { "char_end": 460, "char_start": 459, "chars": "p" }, { "char_end": 462, "char_start": 461, "chars": "r" }, { "char_end": 533, "char_start": 499, "chars": ";\n\tif (!Stream_SafeSeek(irp->input" }, { "char_end": 556, "char_start": 545, "chars": "))\n\t\treturn" }, { "char_end": 576, "char_start": 557, "chars": "ERROR_INVALID_DATA;" }, { "char_end": 584, "char_start": 578, "chars": "status" }, { "char_end": 586, "char_start": 585, "chars": "=" }, { "char_end": 614, "char_start": 587, "chars": "ConvertFromUnicode(CP_UTF8," }, { "char_end": 617, "char_start": 615, "chars": "0," }, { "char_end": 622, "char_start": 618, "chars": "ptr," }, { "char_end": 633, "char_start": 623, "chars": "PathLength" }, { "char_end": 635, "char_start": 634, "chars": "/" }, { "char_end": 638, "char_start": 636, "chars": "2," } ], "deleted": [ { "char_end": 332, "char_start": 331, "chars": "s" }, { "char_end": 345, "char_start": 333, "chars": "atus = Conve" }, { "char_end": 367, "char_start": 346, "chars": "tFromUnicode(CP_UTF8," }, { "char_end": 370, "char_start": 368, "chars": "0," }, { "char_end": 422, "char_start": 417, "chars": " / 2," }, { "char_end": 443, "char_start": 424, "chars": " " } ] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/795842f4096501fcefc1a7f535ccc8132feb31d7", "file_name": "channels/parallel/client/parallel_main.c", "func_name": "parallel_process_irp_create", "line_changes": { "added": [ { "char_end": 125, "char_start": 112, "line": "\tWCHAR* ptr;\n", "line_no": 5 }, { "char_end": 184, "char_start": 145, "line": "\tif (!Stream_SafeSeek(irp->input, 28))\n", "line_no": 7 }, { "char_end": 213, "char_start": 184, "line": "\t\treturn ERROR_INVALID_DATA;\n", "line_no": 8 }, { "char_end": 384, "char_start": 336, "line": "\tif (Stream_GetRemainingLength(irp->input) < 4)\n", "line_no": 11 }, { "char_end": 413, "char_start": 384, "line": "\t\treturn ERROR_INVALID_DATA;\n", "line_no": 12 }, { "char_end": 501, "char_start": 458, "line": "\tptr = (WCHAR*)Stream_Pointer(irp->input);\n", "line_no": 14 }, { "char_end": 548, "char_start": 501, "line": "\tif (!Stream_SafeSeek(irp->input, PathLength))\n", "line_no": 15 }, { "char_end": 577, "char_start": 548, "line": "\t\treturn ERROR_INVALID_DATA;\n", "line_no": 16 }, { "char_end": 662, "char_start": 577, "line": "\tstatus = ConvertFromUnicode(CP_UTF8, 0, ptr, PathLength / 2, &path, 0, NULL, NULL);\n", "line_no": 17 } ], "deleted": [ { "char_end": 162, "char_start": 132, "line": "\tStream_Seek(irp->input, 28);\n", "line_no": 6 }, { "char_end": 423, "char_start": 330, "line": "\tstatus = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*)Stream_Pointer(irp->input), PathLength / 2,\n", "line_no": 10 }, { "char_end": 475, "char_start": 423, "line": "\t &path, 0, NULL, NULL);\n", "line_no": 11 } ] }, "vul_type": "cwe-125" }
469
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "const TfLiteTensor* GetOptionalInputTensor(const TfLiteContext* context,\n const TfLiteNode* node, int index) {", " const bool use_tensor = index < node->inputs->size &&\n node->inputs->data[index] != kTfLiteOptionalTensor;\n if (use_tensor) {\n return GetMutableInput(context, node, index);\n }\n return nullptr;", "}" ]
[ 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [], "deleted": [ { "char_end": 311, "char_start": 155, "chars": "const bool use_tensor = index < node->inputs->size &&\n node->inputs->data[index] != kTfLiteOptionalTensor;\n if (use_tensor) {\n " }, { "char_end": 328, "char_start": 321, "chars": "Mutable" }, { "char_end": 377, "char_start": 355, "chars": ";\n }\n return nullptr" } ] }, "commit_link": "github.com/tensorflow/tensorflow/commit/00302787b788c5ff04cb6f62aed5a74d936e86c0", "file_name": "tensorflow/lite/kernels/kernel_util.cc", "func_name": "tflite::GetOptionalInputTensor", "line_changes": { "added": [ { "char_end": 194, "char_start": 153, "line": " return GetInput(context, node, index);\n", "line_no": 3 } ], "deleted": [ { "char_end": 209, "char_start": 153, "line": " const bool use_tensor = index < node->inputs->size &&\n", "line_no": 3 }, { "char_end": 287, "char_start": 209, "line": " node->inputs->data[index] != kTfLiteOptionalTensor;\n", "line_no": 4 }, { "char_end": 307, "char_start": 287, "line": " if (use_tensor) {\n", "line_no": 5 }, { "char_end": 357, "char_start": 307, "line": " return GetMutableInput(context, node, index);\n", "line_no": 6 }, { "char_end": 361, "char_start": 357, "line": " }\n", "line_no": 7 }, { "char_end": 379, "char_start": 361, "line": " return nullptr;\n", "line_no": 8 } ] }, "vul_type": "cwe-125" }
470
cwe-125
cc
Determine whether the {function_name} code is vulnerable or not.
[ "const TfLiteTensor* GetOptionalInputTensor(const TfLiteContext* context,\n const TfLiteNode* node, int index) {", " return GetInput(context, node, index);", "}" ]
[ 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [], "deleted": [ { "char_end": 311, "char_start": 155, "chars": "const bool use_tensor = index < node->inputs->size &&\n node->inputs->data[index] != kTfLiteOptionalTensor;\n if (use_tensor) {\n " }, { "char_end": 328, "char_start": 321, "chars": "Mutable" }, { "char_end": 377, "char_start": 355, "chars": ";\n }\n return nullptr" } ] }, "commit_link": "github.com/tensorflow/tensorflow/commit/00302787b788c5ff04cb6f62aed5a74d936e86c0", "file_name": "tensorflow/lite/kernels/kernel_util.cc", "func_name": "tflite::GetOptionalInputTensor", "line_changes": { "added": [ { "char_end": 194, "char_start": 153, "line": " return GetInput(context, node, index);\n", "line_no": 3 } ], "deleted": [ { "char_end": 209, "char_start": 153, "line": " const bool use_tensor = index < node->inputs->size &&\n", "line_no": 3 }, { "char_end": 287, "char_start": 209, "line": " node->inputs->data[index] != kTfLiteOptionalTensor;\n", "line_no": 4 }, { "char_end": 307, "char_start": 287, "line": " if (use_tensor) {\n", "line_no": 5 }, { "char_end": 357, "char_start": 307, "line": " return GetMutableInput(context, node, index);\n", "line_no": 6 }, { "char_end": 361, "char_start": 357, "line": " }\n", "line_no": 7 }, { "char_end": 379, "char_start": 361, "line": " return nullptr;\n", "line_no": 8 } ] }, "vul_type": "cwe-125" }
470
cwe-125
cc
Determine whether the {function_name} code is vulnerable or not.
[ "static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,\n ExceptionInfo *exception)\n{\n char\n page_geometry[MaxTextExtent];", " Image\n *image;", " MagickBooleanType\n logging;", " volatile int\n first_mng_object,\n object_id,\n term_chunk_found,\n skip_to_iend;", " volatile ssize_t\n image_count=0;", " MagickBooleanType\n status;", " MagickOffsetType\n offset;", " MngBox\n default_fb,\n fb,\n previous_fb;", "#if defined(MNG_INSERT_LAYERS)\n PixelPacket\n mng_background_color;\n#endif", " register unsigned char\n *p;", " register ssize_t\n i;", " size_t\n count;", " ssize_t\n loop_level;", " volatile short\n skipping_loop;", "#if defined(MNG_INSERT_LAYERS)\n unsigned int\n mandatory_back=0;\n#endif", " volatile unsigned int\n#ifdef MNG_OBJECT_BUFFERS\n mng_background_object=0,\n#endif\n mng_type=0; /* 0: PNG or JNG; 1: MNG; 2: MNG-LC; 3: MNG-VLC */", " size_t\n default_frame_timeout,\n frame_timeout,\n#if defined(MNG_INSERT_LAYERS)\n image_height,\n image_width,\n#endif\n length;", " /* These delays are all measured in image ticks_per_second,\n * not in MNG ticks_per_second\n */\n volatile size_t\n default_frame_delay,\n final_delay,\n final_image_delay,\n frame_delay,\n#if defined(MNG_INSERT_LAYERS)\n insert_layers,\n#endif\n mng_iterations=1,\n simplicity=0,\n subframe_height=0,\n subframe_width=0;", " previous_fb.top=0;\n previous_fb.bottom=0;\n previous_fb.left=0;\n previous_fb.right=0;\n default_fb.top=0;\n default_fb.bottom=0;\n default_fb.left=0;\n default_fb.right=0;", " logging=LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Enter ReadOneMNGImage()\");", " image=mng_info->image;", " if (LocaleCompare(image_info->magick,\"MNG\") == 0)\n {\n char\n magic_number[MaxTextExtent];", " /* Verify MNG signature. */\n count=(size_t) ReadBlob(image,8,(unsigned char *) magic_number);\n if (memcmp(magic_number,\"\\212MNG\\r\\n\\032\\n\",8) != 0)\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");", " /* Initialize some nonzero members of the MngInfo structure. */\n for (i=0; i < MNG_MAX_OBJECTS; i++)\n {\n mng_info->object_clip[i].right=(ssize_t) PNG_UINT_31_MAX;\n mng_info->object_clip[i].bottom=(ssize_t) PNG_UINT_31_MAX;\n }\n mng_info->exists[0]=MagickTrue;\n }", " skipping_loop=(-1);\n first_mng_object=MagickTrue;\n mng_type=0;\n#if defined(MNG_INSERT_LAYERS)\n insert_layers=MagickFalse; /* should be False when converting or mogrifying */\n#endif\n default_frame_delay=0;\n default_frame_timeout=0;\n frame_delay=0;\n final_delay=1;\n mng_info->ticks_per_second=1UL*image->ticks_per_second;\n object_id=0;\n skip_to_iend=MagickFalse;\n term_chunk_found=MagickFalse;\n mng_info->framing_mode=1;\n#if defined(MNG_INSERT_LAYERS)\n mandatory_back=MagickFalse;\n#endif\n#if defined(MNG_INSERT_LAYERS)\n mng_background_color=image->background_color;\n#endif\n default_fb=mng_info->frame;\n previous_fb=mng_info->frame;\n do\n {\n char\n type[MaxTextExtent];", " if (LocaleCompare(image_info->magick,\"MNG\") == 0)\n {\n unsigned char\n *chunk;", " /*\n Read a new chunk.\n */\n type[0]='\\0';\n (void) ConcatenateMagickString(type,\"errr\",MaxTextExtent);\n length=ReadBlobMSBLong(image);\n count=(size_t) ReadBlob(image,4,(unsigned char *) type);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Reading MNG chunk type %c%c%c%c, length: %.20g\",\n type[0],type[1],type[2],type[3],(double) length);", " if (length > PNG_UINT_31_MAX)\n {\n status=MagickFalse;\n break;\n }", " if (count == 0)\n ThrowReaderException(CorruptImageError,\"CorruptImage\");", " p=NULL;\n chunk=(unsigned char *) NULL;", " if (length != 0)\n {\n chunk=(unsigned char *) AcquireQuantumMemory(length+\n MagickPathExtent,sizeof(*chunk));", " if (chunk == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");", " for (i=0; i < (ssize_t) length; i++)\n {\n int\n c;", " c=ReadBlobByte(image);\n if (c == EOF)\n break;\n chunk[i]=(unsigned char) c;\n }", " p=chunk;\n }", " (void) ReadBlobMSBLong(image); /* read crc word */", "#if !defined(JNG_SUPPORTED)\n if (memcmp(type,mng_JHDR,4) == 0)\n {\n skip_to_iend=MagickTrue;", " if (mng_info->jhdr_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"JNGCompressNotSupported\",\"`%s'\",image->filename);", " mng_info->jhdr_warning++;\n }\n#endif\n if (memcmp(type,mng_DHDR,4) == 0)\n {\n skip_to_iend=MagickTrue;", " if (mng_info->dhdr_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"DeltaPNGNotSupported\",\"`%s'\",image->filename);", " mng_info->dhdr_warning++;\n }\n if (memcmp(type,mng_MEND,4) == 0)\n break;", " if (skip_to_iend)\n {\n if (memcmp(type,mng_IEND,4) == 0)\n skip_to_iend=MagickFalse;", " if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Skip to IEND.\");", " continue;\n }", " if (memcmp(type,mng_MHDR,4) == 0)\n {\n if (length != 28)\n {\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n ThrowReaderException(CorruptImageError,\"CorruptImage\");\n }", " mng_info->mng_width=(size_t) ((p[0] << 24) | (p[1] << 16) |\n (p[2] << 8) | p[3]);", " mng_info->mng_height=(size_t) ((p[4] << 24) | (p[5] << 16) |\n (p[6] << 8) | p[7]);", " if (logging != MagickFalse)\n {\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" MNG width: %.20g\",(double) mng_info->mng_width);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" MNG height: %.20g\",(double) mng_info->mng_height);\n }", " p+=8;\n mng_info->ticks_per_second=(size_t) mng_get_long(p);", " if (mng_info->ticks_per_second == 0)\n default_frame_delay=0;", " else\n default_frame_delay=1UL*image->ticks_per_second/\n mng_info->ticks_per_second;", " frame_delay=default_frame_delay;\n simplicity=0;", " /* Skip nominal layer count, frame count, and play time */\n p+=16;\n simplicity=(size_t) mng_get_long(p);", " mng_type=1; /* Full MNG */", " if ((simplicity != 0) && ((simplicity | 11) == 11))\n mng_type=2; /* LC */", " if ((simplicity != 0) && ((simplicity | 9) == 9))\n mng_type=3; /* VLC */", "#if defined(MNG_INSERT_LAYERS)\n if (mng_type != 3)\n insert_layers=MagickTrue;\n#endif\n if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /* Allocate next image structure. */\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n mng_info->image=image;\n }", " if ((mng_info->mng_width > 65535L) ||\n (mng_info->mng_height > 65535L))\n {\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n ThrowReaderException(ImageError,\"WidthOrHeightExceedsLimit\");\n }", " (void) FormatLocaleString(page_geometry,MaxTextExtent,\n \"%.20gx%.20g+0+0\",(double) mng_info->mng_width,(double)\n mng_info->mng_height);", " mng_info->frame.left=0;\n mng_info->frame.right=(ssize_t) mng_info->mng_width;\n mng_info->frame.top=0;\n mng_info->frame.bottom=(ssize_t) mng_info->mng_height;\n mng_info->clip=default_fb=previous_fb=mng_info->frame;", " for (i=0; i < MNG_MAX_OBJECTS; i++)\n mng_info->object_clip[i]=mng_info->frame;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_TERM,4) == 0)\n {\n int\n repeat=0;", " if (length != 0)\n repeat=p[0];", " if (repeat == 3 && length > 8)\n {\n final_delay=(png_uint_32) mng_get_long(&p[2]);\n mng_iterations=(png_uint_32) mng_get_long(&p[6]);", " if (mng_iterations == PNG_UINT_31_MAX)\n mng_iterations=0;", " image->iterations=mng_iterations;\n term_chunk_found=MagickTrue;\n }", " if (logging != MagickFalse)\n {\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" repeat=%d, final_delay=%.20g, iterations=%.20g\",\n repeat,(double) final_delay, (double) image->iterations);\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_DEFI,4) == 0)\n {\n if (mng_type == 3)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"DEFI chunk found in MNG-VLC datastream\",\"`%s'\",\n image->filename);", " if (length > 1)\n {\n object_id=(p[0] << 8) | p[1];", " if (mng_type == 2 && object_id != 0)\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(),\n CoderError,\"Nonzero object_id in MNG-LC datastream\",\n \"`%s'\", image->filename);", " if (object_id > MNG_MAX_OBJECTS)\n {\n /*\n Instead of using a warning we should allocate a larger\n MngInfo structure and continue.\n */\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(), CoderError,\n \"object id too large\",\"`%s'\",image->filename);\n object_id=MNG_MAX_OBJECTS;\n }", " if (mng_info->exists[object_id])\n if (mng_info->frozen[object_id])\n {\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(),CoderError,\n \"DEFI cannot redefine a frozen MNG object\",\"`%s'\",\n image->filename);\n continue;\n }", " mng_info->exists[object_id]=MagickTrue;", " if (length > 2)\n mng_info->invisible[object_id]=p[2];", " /*\n Extract object offset info.\n */\n if (length > 11)\n {\n mng_info->x_off[object_id]=(ssize_t) ((p[4] << 24) |\n (p[5] << 16) | (p[6] << 8) | p[7]);", " mng_info->y_off[object_id]=(ssize_t) ((p[8] << 24) |\n (p[9] << 16) | (p[10] << 8) | p[11]);", " if (logging != MagickFalse)\n {\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" x_off[%d]: %.20g, y_off[%d]: %.20g\",\n object_id,(double) mng_info->x_off[object_id],\n object_id,(double) mng_info->y_off[object_id]);\n }\n }", " /*\n Extract object clipping info.\n */\n \n if (length > 27)\n mng_info->object_clip[object_id]=\n mng_read_box(mng_info->frame,0, &p[12]);\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_bKGD,4) == 0)\n {\n mng_info->have_global_bkgd=MagickFalse;", " if (length > 5)\n {\n mng_info->mng_global_bkgd.red=\n ScaleShortToQuantum((unsigned short) ((p[0] << 8) | p[1]));", " mng_info->mng_global_bkgd.green=\n ScaleShortToQuantum((unsigned short) ((p[2] << 8) | p[3]));", " mng_info->mng_global_bkgd.blue=\n ScaleShortToQuantum((unsigned short) ((p[4] << 8) | p[5]));", " mng_info->have_global_bkgd=MagickTrue;\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_BACK,4) == 0)\n {\n#if defined(MNG_INSERT_LAYERS)\n if (length > 6)\n mandatory_back=p[6];", " else\n mandatory_back=0;", " if (mandatory_back && length > 5)\n {\n mng_background_color.red=\n ScaleShortToQuantum((unsigned short) ((p[0] << 8) | p[1]));", " mng_background_color.green=\n ScaleShortToQuantum((unsigned short) ((p[2] << 8) | p[3]));", " mng_background_color.blue=\n ScaleShortToQuantum((unsigned short) ((p[4] << 8) | p[5]));", " mng_background_color.opacity=OpaqueOpacity;\n }", "#ifdef MNG_OBJECT_BUFFERS\n if (length > 8)\n mng_background_object=(p[7] << 8) | p[8];\n#endif\n#endif\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_PLTE,4) == 0)\n {\n /* Read global PLTE. */", " if (length && (length < 769))\n {\n if (mng_info->global_plte == (png_colorp) NULL)\n mng_info->global_plte=(png_colorp) AcquireQuantumMemory(256,\n sizeof(*mng_info->global_plte));", " for (i=0; i < (ssize_t) (length/3); i++)\n {\n mng_info->global_plte[i].red=p[3*i];\n mng_info->global_plte[i].green=p[3*i+1];\n mng_info->global_plte[i].blue=p[3*i+2];\n }", " mng_info->global_plte_length=(unsigned int) (length/3);\n }\n#ifdef MNG_LOOSE\n for ( ; i < 256; i++)\n {\n mng_info->global_plte[i].red=i;\n mng_info->global_plte[i].green=i;\n mng_info->global_plte[i].blue=i;\n }", " if (length != 0)\n mng_info->global_plte_length=256;\n#endif\n else\n mng_info->global_plte_length=0;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_tRNS,4) == 0)\n {\n /* read global tRNS */", " if (length > 0 && length < 257)\n for (i=0; i < (ssize_t) length; i++)\n mng_info->global_trns[i]=p[i];", "#ifdef MNG_LOOSE\n for ( ; i < 256; i++)\n mng_info->global_trns[i]=255;\n#endif\n mng_info->global_trns_length=(unsigned int) length;\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_gAMA,4) == 0)\n {\n if (length == 4)\n {\n ssize_t\n igamma;", " igamma=mng_get_long(p);\n mng_info->global_gamma=((float) igamma)*0.00001;\n mng_info->have_global_gama=MagickTrue;\n }", " else\n mng_info->have_global_gama=MagickFalse;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_cHRM,4) == 0)\n {\n /* Read global cHRM */", " if (length == 32)\n {\n mng_info->global_chrm.white_point.x=0.00001*mng_get_long(p);\n mng_info->global_chrm.white_point.y=0.00001*mng_get_long(&p[4]);\n mng_info->global_chrm.red_primary.x=0.00001*mng_get_long(&p[8]);\n mng_info->global_chrm.red_primary.y=0.00001*\n mng_get_long(&p[12]);\n mng_info->global_chrm.green_primary.x=0.00001*\n mng_get_long(&p[16]);\n mng_info->global_chrm.green_primary.y=0.00001*\n mng_get_long(&p[20]);\n mng_info->global_chrm.blue_primary.x=0.00001*\n mng_get_long(&p[24]);\n mng_info->global_chrm.blue_primary.y=0.00001*\n mng_get_long(&p[28]);\n mng_info->have_global_chrm=MagickTrue;\n }\n else\n mng_info->have_global_chrm=MagickFalse;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_sRGB,4) == 0)\n {\n /*\n Read global sRGB.\n */\n if (length != 0)\n {\n mng_info->global_srgb_intent=\n Magick_RenderingIntent_from_PNG_RenderingIntent(p[0]);\n mng_info->have_global_srgb=MagickTrue;\n }\n else\n mng_info->have_global_srgb=MagickFalse;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_iCCP,4) == 0)\n {\n /* To do: */", " /*\n Read global iCCP.\n */\n if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " continue;\n }", " if (memcmp(type,mng_FRAM,4) == 0)\n {\n if (mng_type == 3)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"FRAM chunk found in MNG-VLC datastream\",\"`%s'\",\n image->filename);", " if ((mng_info->framing_mode == 2) || (mng_info->framing_mode == 4))\n image->delay=frame_delay;", " frame_delay=default_frame_delay;\n frame_timeout=default_frame_timeout;\n fb=default_fb;", " if (length > 0)\n if (p[0])\n mng_info->framing_mode=p[0];", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Framing_mode=%d\",mng_info->framing_mode);", " if (length > 6)\n {\n /* Note the delay and frame clipping boundaries. */", " p++; /* framing mode */", " while (*p && ((p-chunk) < (ssize_t) length))\n p++; /* frame name */", " p++; /* frame name terminator */", " if ((p-chunk) < (ssize_t) (length-4))\n {\n int\n change_delay,\n change_timeout,\n change_clipping;", " change_delay=(*p++);\n change_timeout=(*p++);\n change_clipping=(*p++);\n p++; /* change_sync */", " if (change_delay && (p-chunk) < (ssize_t) (length-4))\n {\n frame_delay=1UL*image->ticks_per_second*\n mng_get_long(p);", " if (mng_info->ticks_per_second != 0)\n frame_delay/=mng_info->ticks_per_second;", " else\n frame_delay=PNG_UINT_31_MAX;", " if (change_delay == 2)\n default_frame_delay=frame_delay;", " p+=4;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Framing_delay=%.20g\",(double) frame_delay);\n }", " if (change_timeout && (p-chunk) < (ssize_t) (length-4))\n {\n frame_timeout=1UL*image->ticks_per_second*\n mng_get_long(p);", " if (mng_info->ticks_per_second != 0)\n frame_timeout/=mng_info->ticks_per_second;", " else\n frame_timeout=PNG_UINT_31_MAX;", " if (change_timeout == 2)\n default_frame_timeout=frame_timeout;", " p+=4;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Framing_timeout=%.20g\",(double) frame_timeout);\n }", " if (change_clipping && (p-chunk) < (ssize_t) (length-17))\n {\n fb=mng_read_box(previous_fb,(char) p[0],&p[1]);\n p+=17;\n previous_fb=fb;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Frame_clip: L=%.20g R=%.20g T=%.20g B=%.20g\",\n (double) fb.left,(double) fb.right,(double) fb.top,\n (double) fb.bottom);", " if (change_clipping == 2)\n default_fb=fb;\n }\n }\n }\n mng_info->clip=fb;\n mng_info->clip=mng_minimum_box(fb,mng_info->frame);", " subframe_width=(size_t) (mng_info->clip.right\n -mng_info->clip.left);", " subframe_height=(size_t) (mng_info->clip.bottom\n -mng_info->clip.top);\n /*\n Insert a background layer behind the frame if framing_mode is 4.\n */\n#if defined(MNG_INSERT_LAYERS)\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" subframe_width=%.20g, subframe_height=%.20g\",(double)\n subframe_width,(double) subframe_height);", " if (insert_layers && (mng_info->framing_mode == 4) &&\n (subframe_width) && (subframe_height))\n {\n /* Allocate next image structure. */\n if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n }", " mng_info->image=image;", " if (term_chunk_found)\n {\n image->start_loop=MagickTrue;\n image->iterations=mng_iterations;\n term_chunk_found=MagickFalse;\n }", " else\n image->start_loop=MagickFalse;", " image->columns=subframe_width;\n image->rows=subframe_height;\n image->page.width=subframe_width;\n image->page.height=subframe_height;\n image->page.x=mng_info->clip.left;\n image->page.y=mng_info->clip.top;\n image->background_color=mng_background_color;\n image->matte=MagickFalse;\n image->delay=0;\n (void) SetImageBackgroundColor(image);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Insert backgd layer, L=%.20g, R=%.20g T=%.20g, B=%.20g\",\n (double) mng_info->clip.left,(double) mng_info->clip.right,\n (double) mng_info->clip.top,(double) mng_info->clip.bottom);\n }\n#endif\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_CLIP,4) == 0)\n {\n unsigned int\n first_object,\n last_object;", " /*\n Read CLIP.\n */\n if (length > 3)\n {\n first_object=(p[0] << 8) | p[1];\n last_object=(p[2] << 8) | p[3];\n p+=4;", " for (i=(int) first_object; i <= (int) last_object; i++)\n {\n if (mng_info->exists[i] && !mng_info->frozen[i])\n {\n MngBox\n box;", " box=mng_info->object_clip[i];\n if ((p-chunk) < (ssize_t) (length-17))\n mng_info->object_clip[i]=\n mng_read_box(box,(char) p[0],&p[1]);\n }\n }", " }\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_SAVE,4) == 0)\n {\n for (i=1; i < MNG_MAX_OBJECTS; i++)\n if (mng_info->exists[i])\n {\n mng_info->frozen[i]=MagickTrue;\n#ifdef MNG_OBJECT_BUFFERS\n if (mng_info->ob[i] != (MngBuffer *) NULL)\n mng_info->ob[i]->frozen=MagickTrue;\n#endif\n }", " if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " continue;\n }", " if ((memcmp(type,mng_DISC,4) == 0) || (memcmp(type,mng_SEEK,4) == 0))\n {\n /* Read DISC or SEEK. */", " if ((length == 0) || !memcmp(type,mng_SEEK,4))\n {\n for (i=1; i < MNG_MAX_OBJECTS; i++)\n MngInfoDiscardObject(mng_info,i);\n }", " else\n {\n register ssize_t\n j;", " for (j=1; j < (ssize_t) length; j+=2)\n {\n i=p[j-1] << 8 | p[j];\n MngInfoDiscardObject(mng_info,i);\n }\n }", " if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " continue;\n }", " if (memcmp(type,mng_MOVE,4) == 0)\n {\n size_t\n first_object,\n last_object;", " /* read MOVE */", " if (length > 3)\n {\n first_object=(p[0] << 8) | p[1];\n last_object=(p[2] << 8) | p[3];\n p+=4;", " for (i=(ssize_t) first_object; i <= (ssize_t) last_object; i++)\n {", "", " if (mng_info->exists[i] && !mng_info->frozen[i] &&\n (p-chunk) < (ssize_t) (length-8))\n {\n MngPair\n new_pair;", " MngPair\n old_pair;", " old_pair.a=mng_info->x_off[i];\n old_pair.b=mng_info->y_off[i];\n new_pair=mng_read_pair(old_pair,(int) p[0],&p[1]);\n mng_info->x_off[i]=new_pair.a;\n mng_info->y_off[i]=new_pair.b;\n }\n }\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_LOOP,4) == 0)\n {\n ssize_t loop_iters=1;\n if (length > 4)\n {\n loop_level=chunk[0];\n mng_info->loop_active[loop_level]=1; /* mark loop active */", " /* Record starting point. */\n loop_iters=mng_get_long(&chunk[1]);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" LOOP level %.20g has %.20g iterations \",\n (double) loop_level, (double) loop_iters);", " if (loop_iters == 0)\n skipping_loop=loop_level;", " else\n {\n mng_info->loop_jump[loop_level]=TellBlob(image);\n mng_info->loop_count[loop_level]=loop_iters;\n }", " mng_info->loop_iteration[loop_level]=0;\n }\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_ENDL,4) == 0)\n {\n if (length > 0)\n {\n loop_level=chunk[0];", " if (skipping_loop > 0)\n {\n if (skipping_loop == loop_level)\n {\n /*\n Found end of zero-iteration loop.\n */\n skipping_loop=(-1);\n mng_info->loop_active[loop_level]=0;\n }\n }", " else\n {\n if (mng_info->loop_active[loop_level] == 1)\n {\n mng_info->loop_count[loop_level]--;\n mng_info->loop_iteration[loop_level]++;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" ENDL: LOOP level %.20g has %.20g remaining iters \",\n (double) loop_level,(double)\n mng_info->loop_count[loop_level]);", " if (mng_info->loop_count[loop_level] != 0)\n {\n offset=SeekBlob(image,\n mng_info->loop_jump[loop_level], SEEK_SET);", " if (offset < 0)\n {\n chunk=(unsigned char *) RelinquishMagickMemory(\n chunk);\n ThrowReaderException(CorruptImageError,\n \"ImproperImageHeader\");\n }\n }", " else\n {\n short\n last_level;", " /*\n Finished loop.\n */\n mng_info->loop_active[loop_level]=0;\n last_level=(-1);\n for (i=0; i < loop_level; i++)\n if (mng_info->loop_active[i] == 1)\n last_level=(short) i;\n loop_level=last_level;\n }\n }\n }\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_CLON,4) == 0)\n {\n if (mng_info->clon_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"CLON is not implemented yet\",\"`%s'\",\n image->filename);", " mng_info->clon_warning++;\n }", " if (memcmp(type,mng_MAGN,4) == 0)\n {\n png_uint_16\n magn_first,\n magn_last,\n magn_mb,\n magn_ml,\n magn_mr,\n magn_mt,\n magn_mx,\n magn_my,\n magn_methx,\n magn_methy;", " if (length > 1)\n magn_first=(p[0] << 8) | p[1];", " else\n magn_first=0;", " if (length > 3)\n magn_last=(p[2] << 8) | p[3];", " else\n magn_last=magn_first;\n#ifndef MNG_OBJECT_BUFFERS\n if (magn_first || magn_last)\n if (mng_info->magn_warning == 0)\n {\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(),CoderError,\n \"MAGN is not implemented yet for nonzero objects\",\n \"`%s'\",image->filename);", " mng_info->magn_warning++;\n }\n#endif\n if (length > 4)\n magn_methx=p[4];", " else\n magn_methx=0;", " if (length > 6)\n magn_mx=(p[5] << 8) | p[6];", " else\n magn_mx=1;", " if (magn_mx == 0)\n magn_mx=1;", " if (length > 8)\n magn_my=(p[7] << 8) | p[8];", " else\n magn_my=magn_mx;", " if (magn_my == 0)\n magn_my=1;", " if (length > 10)\n magn_ml=(p[9] << 8) | p[10];", " else\n magn_ml=magn_mx;", " if (magn_ml == 0)\n magn_ml=1;", " if (length > 12)\n magn_mr=(p[11] << 8) | p[12];", " else\n magn_mr=magn_mx;", " if (magn_mr == 0)\n magn_mr=1;", " if (length > 14)\n magn_mt=(p[13] << 8) | p[14];", " else\n magn_mt=magn_my;", " if (magn_mt == 0)\n magn_mt=1;", " if (length > 16)\n magn_mb=(p[15] << 8) | p[16];", " else\n magn_mb=magn_my;", " if (magn_mb == 0)\n magn_mb=1;", " if (length > 17)\n magn_methy=p[17];", " else\n magn_methy=magn_methx;", "\n if (magn_methx > 5 || magn_methy > 5)\n if (mng_info->magn_warning == 0)\n {\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(),CoderError,\n \"Unknown MAGN method in MNG datastream\",\"`%s'\",\n image->filename);", " mng_info->magn_warning++;\n }\n#ifdef MNG_OBJECT_BUFFERS\n /* Magnify existing objects in the range magn_first to magn_last */\n#endif\n if (magn_first == 0 || magn_last == 0)\n {\n /* Save the magnification factors for object 0 */\n mng_info->magn_mb=magn_mb;\n mng_info->magn_ml=magn_ml;\n mng_info->magn_mr=magn_mr;\n mng_info->magn_mt=magn_mt;\n mng_info->magn_mx=magn_mx;\n mng_info->magn_my=magn_my;\n mng_info->magn_methx=magn_methx;\n mng_info->magn_methy=magn_methy;\n }\n }", " if (memcmp(type,mng_PAST,4) == 0)\n {\n if (mng_info->past_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"PAST is not implemented yet\",\"`%s'\",\n image->filename);", " mng_info->past_warning++;\n }", " if (memcmp(type,mng_SHOW,4) == 0)\n {\n if (mng_info->show_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"SHOW is not implemented yet\",\"`%s'\",\n image->filename);", " mng_info->show_warning++;\n }", " if (memcmp(type,mng_sBIT,4) == 0)\n {\n if (length < 4)\n mng_info->have_global_sbit=MagickFalse;", " else\n {\n mng_info->global_sbit.gray=p[0];\n mng_info->global_sbit.red=p[0];\n mng_info->global_sbit.green=p[1];\n mng_info->global_sbit.blue=p[2];\n mng_info->global_sbit.alpha=p[3];\n mng_info->have_global_sbit=MagickTrue;\n }\n }\n if (memcmp(type,mng_pHYs,4) == 0)\n {\n if (length > 8)\n {\n mng_info->global_x_pixels_per_unit=\n (size_t) mng_get_long(p);\n mng_info->global_y_pixels_per_unit=\n (size_t) mng_get_long(&p[4]);\n mng_info->global_phys_unit_type=p[8];\n mng_info->have_global_phys=MagickTrue;\n }", " else\n mng_info->have_global_phys=MagickFalse;\n }\n if (memcmp(type,mng_pHYg,4) == 0)\n {\n if (mng_info->phyg_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"pHYg is not implemented.\",\"`%s'\",image->filename);", " mng_info->phyg_warning++;\n }\n if (memcmp(type,mng_BASI,4) == 0)\n {\n skip_to_iend=MagickTrue;", " if (mng_info->basi_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"BASI is not implemented yet\",\"`%s'\",\n image->filename);", " mng_info->basi_warning++;\n#ifdef MNG_BASI_SUPPORTED\n if (length > 11)\n {\n basi_width=(size_t) ((p[0] << 24) | (p[1] << 16) |\n (p[2] << 8) | p[3]);\n basi_height=(size_t) ((p[4] << 24) | (p[5] << 16) |\n (p[6] << 8) | p[7]);\n basi_color_type=p[8];\n basi_compression_method=p[9];\n basi_filter_type=p[10];\n basi_interlace_method=p[11];\n }\n if (length > 13)\n basi_red=(p[12] << 8) & p[13];", " else\n basi_red=0;", " if (length > 15)\n basi_green=(p[14] << 8) & p[15];", " else\n basi_green=0;", " if (length > 17)\n basi_blue=(p[16] << 8) & p[17];", " else\n basi_blue=0;", " if (length > 19)\n basi_alpha=(p[18] << 8) & p[19];", " else\n {\n if (basi_sample_depth == 16)\n basi_alpha=65535L;\n else\n basi_alpha=255;\n }", " if (length > 20)\n basi_viewable=p[20];", " else\n basi_viewable=0;", "#endif\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_IHDR,4)\n#if defined(JNG_SUPPORTED)\n && memcmp(type,mng_JHDR,4)\n#endif\n )\n {\n /* Not an IHDR or JHDR chunk */\n if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " continue;\n }\n/* Process IHDR */\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Processing %c%c%c%c chunk\",type[0],type[1],type[2],type[3]);", " mng_info->exists[object_id]=MagickTrue;\n mng_info->viewable[object_id]=MagickTrue;", " if (mng_info->invisible[object_id])\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Skipping invisible object\");", " skip_to_iend=MagickTrue;\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n#if defined(MNG_INSERT_LAYERS)\n if (length < 8)\n {\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n }", " image_width=(size_t) mng_get_long(p);\n image_height=(size_t) mng_get_long(&p[4]);\n#endif\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " /*\n Insert a transparent background layer behind the entire animation\n if it is not full screen.\n */\n#if defined(MNG_INSERT_LAYERS)\n if (insert_layers && mng_type && first_mng_object)\n {\n if ((mng_info->clip.left > 0) || (mng_info->clip.top > 0) ||\n (image_width < mng_info->mng_width) ||\n (mng_info->clip.right < (ssize_t) mng_info->mng_width) ||\n (image_height < mng_info->mng_height) ||\n (mng_info->clip.bottom < (ssize_t) mng_info->mng_height))\n {\n if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n }\n mng_info->image=image;", " if (term_chunk_found)\n {\n image->start_loop=MagickTrue;\n image->iterations=mng_iterations;\n term_chunk_found=MagickFalse;\n }", " else\n image->start_loop=MagickFalse;", " /* Make a background rectangle. */", " image->delay=0;\n image->columns=mng_info->mng_width;\n image->rows=mng_info->mng_height;\n image->page.width=mng_info->mng_width;\n image->page.height=mng_info->mng_height;\n image->page.x=0;\n image->page.y=0;\n image->background_color=mng_background_color;\n (void) SetImageBackgroundColor(image);\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Inserted transparent background layer, W=%.20g, H=%.20g\",\n (double) mng_info->mng_width,(double) mng_info->mng_height);\n }\n }\n /*\n Insert a background layer behind the upcoming image if\n framing_mode is 3, and we haven't already inserted one.\n */\n if (insert_layers && (mng_info->framing_mode == 3) &&\n (subframe_width) && (subframe_height) && (simplicity == 0 ||\n (simplicity & 0x08)))\n {\n if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n }", " mng_info->image=image;", " if (term_chunk_found)\n {\n image->start_loop=MagickTrue;\n image->iterations=mng_iterations;\n term_chunk_found=MagickFalse;\n }", " else\n image->start_loop=MagickFalse;", " image->delay=0;\n image->columns=subframe_width;\n image->rows=subframe_height;\n image->page.width=subframe_width;\n image->page.height=subframe_height;\n image->page.x=mng_info->clip.left;\n image->page.y=mng_info->clip.top;\n image->background_color=mng_background_color;\n image->matte=MagickFalse;\n (void) SetImageBackgroundColor(image);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Insert background layer, L=%.20g, R=%.20g T=%.20g, B=%.20g\",\n (double) mng_info->clip.left,(double) mng_info->clip.right,\n (double) mng_info->clip.top,(double) mng_info->clip.bottom);\n }\n#endif /* MNG_INSERT_LAYERS */\n first_mng_object=MagickFalse;", " if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n }\n mng_info->image=image;\n status=SetImageProgress(image,LoadImagesTag,TellBlob(image),\n GetBlobSize(image));", " if (status == MagickFalse)\n break;", " if (term_chunk_found)\n {\n image->start_loop=MagickTrue;\n term_chunk_found=MagickFalse;\n }", " else\n image->start_loop=MagickFalse;", " if (mng_info->framing_mode == 1 || mng_info->framing_mode == 3)\n {\n image->delay=frame_delay;\n frame_delay=default_frame_delay;\n }", " else\n image->delay=0;", " image->page.width=mng_info->mng_width;\n image->page.height=mng_info->mng_height;\n image->page.x=mng_info->x_off[object_id];\n image->page.y=mng_info->y_off[object_id];\n image->iterations=mng_iterations;", " /*\n Seek back to the beginning of the IHDR or JHDR chunk's length field.\n */", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Seeking back to beginning of %c%c%c%c chunk\",type[0],type[1],\n type[2],type[3]);", " offset=SeekBlob(image,-((ssize_t) length+12),SEEK_CUR);", " if (offset < 0)\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n }", " mng_info->image=image;\n mng_info->mng_type=mng_type;\n mng_info->object_id=object_id;", " if (memcmp(type,mng_IHDR,4) == 0)\n image=ReadOnePNGImage(mng_info,image_info,exception);", "#if defined(JNG_SUPPORTED)\n else\n image=ReadOneJNGImage(mng_info,image_info,exception);\n#endif", " if (image == (Image *) NULL)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \"exit ReadJNGImage() with error\");", " return((Image *) NULL);\n }", " if (image->columns == 0 || image->rows == 0)\n {\n (void) CloseBlob(image);\n return(DestroyImageList(image));\n }", " mng_info->image=image;", " if (mng_type)\n {\n MngBox\n crop_box;", " if (mng_info->magn_methx || mng_info->magn_methy)\n {\n png_uint_32\n magnified_height,\n magnified_width;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Processing MNG MAGN chunk\");", " if (mng_info->magn_methx == 1)\n {\n magnified_width=mng_info->magn_ml;", " if (image->columns > 1)\n magnified_width += mng_info->magn_mr;", " if (image->columns > 2)\n magnified_width += (png_uint_32)\n ((image->columns-2)*(mng_info->magn_mx));\n }", " else\n {\n magnified_width=(png_uint_32) image->columns;", " if (image->columns > 1)\n magnified_width += mng_info->magn_ml-1;", " if (image->columns > 2)\n magnified_width += mng_info->magn_mr-1;", " if (image->columns > 3)\n magnified_width += (png_uint_32)\n ((image->columns-3)*(mng_info->magn_mx-1));\n }", " if (mng_info->magn_methy == 1)\n {\n magnified_height=mng_info->magn_mt;", " if (image->rows > 1)\n magnified_height += mng_info->magn_mb;", " if (image->rows > 2)\n magnified_height += (png_uint_32)\n ((image->rows-2)*(mng_info->magn_my));\n }", " else\n {\n magnified_height=(png_uint_32) image->rows;", " if (image->rows > 1)\n magnified_height += mng_info->magn_mt-1;", " if (image->rows > 2)\n magnified_height += mng_info->magn_mb-1;", " if (image->rows > 3)\n magnified_height += (png_uint_32)\n ((image->rows-3)*(mng_info->magn_my-1));\n }", " if (magnified_height > image->rows ||\n magnified_width > image->columns)\n {\n Image\n *large_image;", " int\n yy;", " ssize_t\n m,\n y;", " register ssize_t\n x;", " register PixelPacket\n *n,\n *q;", " PixelPacket\n *next,\n *prev;", " png_uint_16\n magn_methx,\n magn_methy;", " /* Allocate next image structure. */", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Allocate magnified image\");", " AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " large_image=SyncNextImageInList(image);", " large_image->columns=magnified_width;\n large_image->rows=magnified_height;", " magn_methx=mng_info->magn_methx;\n magn_methy=mng_info->magn_methy;", "#if (MAGICKCORE_QUANTUM_DEPTH > 16)\n#define QM unsigned short\n if (magn_methx != 1 || magn_methy != 1)\n {\n /*\n Scale pixels to unsigned shorts to prevent\n overflow of intermediate values of interpolations\n */\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=GetAuthenticPixels(image,0,y,image->columns,1,\n exception);", " for (x=(ssize_t) image->columns-1; x >= 0; x--)\n {\n SetPixelRed(q,ScaleQuantumToShort(\n GetPixelRed(q)));\n SetPixelGreen(q,ScaleQuantumToShort(\n GetPixelGreen(q)));\n SetPixelBlue(q,ScaleQuantumToShort(\n GetPixelBlue(q)));\n SetPixelOpacity(q,ScaleQuantumToShort(\n GetPixelOpacity(q)));\n q++;\n }", " if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n }\n }\n#else\n#define QM Quantum\n#endif", " if (image->matte != MagickFalse)\n (void) SetImageBackgroundColor(large_image);", " else\n {\n large_image->background_color.opacity=OpaqueOpacity;\n (void) SetImageBackgroundColor(large_image);", " if (magn_methx == 4)\n magn_methx=2;", " if (magn_methx == 5)\n magn_methx=3;", " if (magn_methy == 4)\n magn_methy=2;", " if (magn_methy == 5)\n magn_methy=3;\n }", " /* magnify the rows into the right side of the large image */", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Magnify the rows to %.20g\",(double) large_image->rows);\n m=(ssize_t) mng_info->magn_mt;\n yy=0;\n length=(size_t) image->columns;\n next=(PixelPacket *) AcquireQuantumMemory(length,sizeof(*next));\n prev=(PixelPacket *) AcquireQuantumMemory(length,sizeof(*prev));", " if ((prev == (PixelPacket *) NULL) ||\n (next == (PixelPacket *) NULL))\n {\n image=DestroyImageList(image);\n ThrowReaderException(ResourceLimitError,\n \"MemoryAllocationFailed\");\n }", " n=GetAuthenticPixels(image,0,0,image->columns,1,exception);\n (void) CopyMagickMemory(next,n,length);", " for (y=0; y < (ssize_t) image->rows; y++)\n {\n if (y == 0)\n m=(ssize_t) mng_info->magn_mt;", " else if (magn_methy > 1 && y == (ssize_t) image->rows-2)\n m=(ssize_t) mng_info->magn_mb;", " else if (magn_methy <= 1 && y == (ssize_t) image->rows-1)\n m=(ssize_t) mng_info->magn_mb;", " else if (magn_methy > 1 && y == (ssize_t) image->rows-1)\n m=1;", " else\n m=(ssize_t) mng_info->magn_my;", " n=prev;\n prev=next;\n next=n;", " if (y < (ssize_t) image->rows-1)\n {\n n=GetAuthenticPixels(image,0,y+1,image->columns,1,\n exception);\n (void) CopyMagickMemory(next,n,length);\n }", " for (i=0; i < m; i++, yy++)\n {\n register PixelPacket\n *pixels;", " assert(yy < (ssize_t) large_image->rows);\n pixels=prev;\n n=next;\n q=GetAuthenticPixels(large_image,0,yy,large_image->columns,\n 1,exception);\n q+=(large_image->columns-image->columns);", " for (x=(ssize_t) image->columns-1; x >= 0; x--)\n {\n /* To do: get color as function of indexes[x] */\n /*\n if (image->storage_class == PseudoClass)\n {\n }\n */", " if (magn_methy <= 1)\n {\n /* replicate previous */\n SetPixelRGBO(q,(pixels));\n }", " else if (magn_methy == 2 || magn_methy == 4)\n {\n if (i == 0)\n {\n SetPixelRGBO(q,(pixels));\n }", " else\n {\n /* Interpolate */\n SetPixelRed(q,\n ((QM) (((ssize_t)\n (2*i*(GetPixelRed(n)\n -GetPixelRed(pixels)+m))/\n ((ssize_t) (m*2))\n +GetPixelRed(pixels)))));\n SetPixelGreen(q,\n ((QM) (((ssize_t)\n (2*i*(GetPixelGreen(n)\n -GetPixelGreen(pixels)+m))/\n ((ssize_t) (m*2))\n +GetPixelGreen(pixels)))));\n SetPixelBlue(q,\n ((QM) (((ssize_t)\n (2*i*(GetPixelBlue(n)\n -GetPixelBlue(pixels)+m))/\n ((ssize_t) (m*2))\n +GetPixelBlue(pixels)))));", " if (image->matte != MagickFalse)\n SetPixelOpacity(q,\n ((QM) (((ssize_t)\n (2*i*(GetPixelOpacity(n)\n -GetPixelOpacity(pixels)+m))\n /((ssize_t) (m*2))+\n GetPixelOpacity(pixels)))));\n }", " if (magn_methy == 4)\n {\n /* Replicate nearest */\n if (i <= ((m+1) << 1))\n SetPixelOpacity(q,\n (*pixels).opacity+0);\n else\n SetPixelOpacity(q,\n (*n).opacity+0);\n }\n }", " else /* if (magn_methy == 3 || magn_methy == 5) */\n {\n /* Replicate nearest */\n if (i <= ((m+1) << 1))\n {\n SetPixelRGBO(q,(pixels));\n }", " else\n {\n SetPixelRGBO(q,(n));\n }", " if (magn_methy == 5)\n {\n SetPixelOpacity(q,\n (QM) (((ssize_t) (2*i*\n (GetPixelOpacity(n)\n -GetPixelOpacity(pixels))\n +m))/((ssize_t) (m*2))\n +GetPixelOpacity(pixels)));\n }\n }\n n++;\n q++;\n pixels++;\n } /* x */", " if (SyncAuthenticPixels(large_image,exception) == 0)\n break;", " } /* i */\n } /* y */", " prev=(PixelPacket *) RelinquishMagickMemory(prev);\n next=(PixelPacket *) RelinquishMagickMemory(next);", " length=image->columns;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Delete original image\");", " DeleteImageFromList(&image);", " image=large_image;", " mng_info->image=image;", " /* magnify the columns */\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Magnify the columns to %.20g\",(double) image->columns);", " for (y=0; y < (ssize_t) image->rows; y++)\n {\n register PixelPacket\n *pixels;", " q=GetAuthenticPixels(image,0,y,image->columns,1,exception);\n pixels=q+(image->columns-length);\n n=pixels+1;", " for (x=(ssize_t) (image->columns-length);\n x < (ssize_t) image->columns; x++)\n {\n /* To do: Rewrite using Get/Set***PixelComponent() */", " if (x == (ssize_t) (image->columns-length))\n m=(ssize_t) mng_info->magn_ml;", " else if (magn_methx > 1 && x == (ssize_t) image->columns-2)\n m=(ssize_t) mng_info->magn_mr;", " else if (magn_methx <= 1 && x == (ssize_t) image->columns-1)\n m=(ssize_t) mng_info->magn_mr;", " else if (magn_methx > 1 && x == (ssize_t) image->columns-1)\n m=1;", " else\n m=(ssize_t) mng_info->magn_mx;", " for (i=0; i < m; i++)\n {\n if (magn_methx <= 1)\n {\n /* replicate previous */\n SetPixelRGBO(q,(pixels));\n }", " else if (magn_methx == 2 || magn_methx == 4)\n {\n if (i == 0)\n {\n SetPixelRGBO(q,(pixels));\n }", " /* To do: Rewrite using Get/Set***PixelComponent() */\n else\n {\n /* Interpolate */\n SetPixelRed(q,\n (QM) ((2*i*(\n GetPixelRed(n)\n -GetPixelRed(pixels))+m)\n /((ssize_t) (m*2))+\n GetPixelRed(pixels)));", " SetPixelGreen(q,\n (QM) ((2*i*(\n GetPixelGreen(n)\n -GetPixelGreen(pixels))+m)\n /((ssize_t) (m*2))+\n GetPixelGreen(pixels)));", " SetPixelBlue(q,\n (QM) ((2*i*(\n GetPixelBlue(n)\n -GetPixelBlue(pixels))+m)\n /((ssize_t) (m*2))+\n GetPixelBlue(pixels)));\n if (image->matte != MagickFalse)\n SetPixelOpacity(q,\n (QM) ((2*i*(\n GetPixelOpacity(n)\n -GetPixelOpacity(pixels))+m)\n /((ssize_t) (m*2))+\n GetPixelOpacity(pixels)));\n }", " if (magn_methx == 4)\n {\n /* Replicate nearest */\n if (i <= ((m+1) << 1))\n {\n SetPixelOpacity(q,\n GetPixelOpacity(pixels)+0);\n }\n else\n {\n SetPixelOpacity(q,\n GetPixelOpacity(n)+0);\n }\n }\n }", " else /* if (magn_methx == 3 || magn_methx == 5) */\n {\n /* Replicate nearest */\n if (i <= ((m+1) << 1))\n {\n SetPixelRGBO(q,(pixels));\n }", " else\n {\n SetPixelRGBO(q,(n));\n }", " if (magn_methx == 5)\n {\n /* Interpolate */\n SetPixelOpacity(q,\n (QM) ((2*i*( GetPixelOpacity(n)\n -GetPixelOpacity(pixels))+m)/\n ((ssize_t) (m*2))\n +GetPixelOpacity(pixels)));\n }\n }\n q++;\n }\n n++;\n }", " if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n }\n#if (MAGICKCORE_QUANTUM_DEPTH > 16)\n if (magn_methx != 1 || magn_methy != 1)\n {\n /*\n Rescale pixels to Quantum\n */\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=GetAuthenticPixels(image,0,y,image->columns,1,exception);", " for (x=(ssize_t) image->columns-1; x >= 0; x--)\n {\n SetPixelRed(q,ScaleShortToQuantum(\n GetPixelRed(q)));\n SetPixelGreen(q,ScaleShortToQuantum(\n GetPixelGreen(q)));\n SetPixelBlue(q,ScaleShortToQuantum(\n GetPixelBlue(q)));\n SetPixelOpacity(q,ScaleShortToQuantum(\n GetPixelOpacity(q)));\n q++;\n }", " if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n }\n }\n#endif\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Finished MAGN processing\");\n }\n }", " /*\n Crop_box is with respect to the upper left corner of the MNG.\n */\n crop_box.left=mng_info->image_box.left+mng_info->x_off[object_id];\n crop_box.right=mng_info->image_box.right+mng_info->x_off[object_id];\n crop_box.top=mng_info->image_box.top+mng_info->y_off[object_id];\n crop_box.bottom=mng_info->image_box.bottom+mng_info->y_off[object_id];\n crop_box=mng_minimum_box(crop_box,mng_info->clip);\n crop_box=mng_minimum_box(crop_box,mng_info->frame);\n crop_box=mng_minimum_box(crop_box,mng_info->object_clip[object_id]);\n if ((crop_box.left != (mng_info->image_box.left\n +mng_info->x_off[object_id])) ||\n (crop_box.right != (mng_info->image_box.right\n +mng_info->x_off[object_id])) ||\n (crop_box.top != (mng_info->image_box.top\n +mng_info->y_off[object_id])) ||\n (crop_box.bottom != (mng_info->image_box.bottom\n +mng_info->y_off[object_id])))\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Crop the PNG image\");", " if ((crop_box.left < crop_box.right) &&\n (crop_box.top < crop_box.bottom))\n {\n Image\n *im;", " RectangleInfo\n crop_info;", " /*\n Crop_info is with respect to the upper left corner of\n the image.\n */\n crop_info.x=(crop_box.left-mng_info->x_off[object_id]);\n crop_info.y=(crop_box.top-mng_info->y_off[object_id]);\n crop_info.width=(size_t) (crop_box.right-crop_box.left);\n crop_info.height=(size_t) (crop_box.bottom-crop_box.top);\n image->page.width=image->columns;\n image->page.height=image->rows;\n image->page.x=0;\n image->page.y=0;\n im=CropImage(image,&crop_info,exception);", " if (im != (Image *) NULL)\n {\n image->columns=im->columns;\n image->rows=im->rows;\n im=DestroyImage(im);\n image->page.width=image->columns;\n image->page.height=image->rows;\n image->page.x=crop_box.left;\n image->page.y=crop_box.top;\n }\n }", " else\n {\n /*\n No pixels in crop area. The MNG spec still requires\n a layer, though, so make a single transparent pixel in\n the top left corner.\n */\n image->columns=1;\n image->rows=1;\n image->colors=2;\n (void) SetImageBackgroundColor(image);\n image->page.width=1;\n image->page.height=1;\n image->page.x=0;\n image->page.y=0;\n }\n }\n#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED\n image=mng_info->image;\n#endif\n }", "#if (MAGICKCORE_QUANTUM_DEPTH > 16)\n /* PNG does not handle depths greater than 16 so reduce it even\n * if lossy, and promote any depths > 8 to 16.\n */\n if (image->depth > 16)\n image->depth=16;\n#endif", "#if (MAGICKCORE_QUANTUM_DEPTH > 8)\n if (image->depth > 8)\n {\n /* To do: fill low byte properly */\n image->depth=16;\n }", " if (LosslessReduceDepthOK(image) != MagickFalse)\n image->depth = 8;\n#endif", " GetImageException(image,exception);", " if (image_info->number_scenes != 0)\n {\n if (mng_info->scenes_found >\n (ssize_t) (image_info->first_scene+image_info->number_scenes))\n break;\n }", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Finished reading image datastream.\");", " } while (LocaleCompare(image_info->magick,\"MNG\") == 0);", " (void) CloseBlob(image);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Finished reading all image datastreams.\");", "#if defined(MNG_INSERT_LAYERS)\n if (insert_layers && !mng_info->image_found && (mng_info->mng_width) &&\n (mng_info->mng_height))\n {\n /*\n Insert a background layer if nothing else was found.\n */\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" No images found. Inserting a background layer.\");", " if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);\n if (GetNextImageInList(image) == (Image *) NULL)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Allocation failed, returning NULL.\");", " return(DestroyImageList(image));\n }\n image=SyncNextImageInList(image);\n }\n image->columns=mng_info->mng_width;\n image->rows=mng_info->mng_height;\n image->page.width=mng_info->mng_width;\n image->page.height=mng_info->mng_height;\n image->page.x=0;\n image->page.y=0;\n image->background_color=mng_background_color;\n image->matte=MagickFalse;", " if (image_info->ping == MagickFalse)\n (void) SetImageBackgroundColor(image);", " mng_info->image_found++;\n }\n#endif\n image->iterations=mng_iterations;", " if (mng_iterations == 1)\n image->start_loop=MagickTrue;", " while (GetPreviousImageInList(image) != (Image *) NULL)\n {\n image_count++;\n if (image_count > 10*mng_info->image_found)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" No beginning\");", " (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"Linked list is corrupted, beginning of list not found\",\n \"`%s'\",image_info->filename);", " return(DestroyImageList(image));\n }", " image=GetPreviousImageInList(image);", " if (GetNextImageInList(image) == (Image *) NULL)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" Corrupt list\");", " (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"Linked list is corrupted; next_image is NULL\",\"`%s'\",\n image_info->filename);\n }\n }", " if (mng_info->ticks_per_second && mng_info->image_found > 1 &&\n GetNextImageInList(image) ==\n (Image *) NULL)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" First image null\");", " (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"image->next for first image is NULL but shouldn't be.\",\n \"`%s'\",image_info->filename);\n }", " if (mng_info->image_found == 0)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" No visible images found.\");", " (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"No visible images in file\",\"`%s'\",image_info->filename);", " return(DestroyImageList(image));\n }", " if (mng_info->ticks_per_second)\n final_delay=1UL*MagickMax(image->ticks_per_second,1L)*\n final_delay/mng_info->ticks_per_second;", " else\n image->start_loop=MagickTrue;", " /* Find final nonzero image delay */\n final_image_delay=0;", " while (GetNextImageInList(image) != (Image *) NULL)\n {\n if (image->delay)\n final_image_delay=image->delay;", " image=GetNextImageInList(image);\n }", " if (final_delay < final_image_delay)\n final_delay=final_image_delay;", " image->delay=final_delay;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" image->delay=%.20g, final_delay=%.20g\",(double) image->delay,\n (double) final_delay);", " if (logging != MagickFalse)\n {\n int\n scene;", " scene=0;\n image=GetFirstImageInList(image);", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Before coalesce:\");", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" scene 0 delay=%.20g\",(double) image->delay);", " while (GetNextImageInList(image) != (Image *) NULL)\n {\n image=GetNextImageInList(image);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" scene %.20g delay=%.20g\",(double) scene++,(double) image->delay);\n }\n }", " image=GetFirstImageInList(image);\n#ifdef MNG_COALESCE_LAYERS\n if (insert_layers)\n {\n Image\n *next_image,\n *next;", " size_t\n scene;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" Coalesce Images\");", " scene=image->scene;\n next_image=CoalesceImages(image,&image->exception);", " if (next_image == (Image *) NULL)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");", " image=DestroyImageList(image);\n image=next_image;", " for (next=image; next != (Image *) NULL; next=next_image)\n {\n next->page.width=mng_info->mng_width;\n next->page.height=mng_info->mng_height;\n next->page.x=0;\n next->page.y=0;\n next->scene=scene++;\n next_image=GetNextImageInList(next);", " if (next_image == (Image *) NULL)\n break;", " if (next->delay == 0)\n {\n scene--;\n next_image->previous=GetPreviousImageInList(next);\n if (GetPreviousImageInList(next) == (Image *) NULL)\n image=next_image;\n else\n next->previous->next=next_image;\n next=DestroyImage(next);\n }\n }\n }\n#endif", " while (GetNextImageInList(image) != (Image *) NULL)\n image=GetNextImageInList(image);", " image->dispose=BackgroundDispose;", " if (logging != MagickFalse)\n {\n int\n scene;", " scene=0;\n image=GetFirstImageInList(image);", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" After coalesce:\");", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" scene 0 delay=%.20g dispose=%.20g\",(double) image->delay,\n (double) image->dispose);", " while (GetNextImageInList(image) != (Image *) NULL)\n {\n image=GetNextImageInList(image);", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" scene %.20g delay=%.20g dispose=%.20g\",(double) scene++,\n (double) image->delay,(double) image->dispose);\n }\n }", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" exit ReadOneJNGImage();\");", " return(image);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 27456, "char_start": 27373, "chars": "(i < 0) || (i >= MNG_MAX_OBJECTS))\n continue;\n if (" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/78d4c5db50fbab0b4beb69c46c6167f2c6513dec", "file_name": "coders/png.c", "func_name": "ReadOneMNGImage", "line_changes": { "added": [ { "char_end": 27408, "char_start": 27353, "line": " if ((i < 0) || (i >= MNG_MAX_OBJECTS))\n", "line_no": 885 }, { "char_end": 27436, "char_start": 27408, "line": " continue;\n", "line_no": 886 } ], "deleted": [] }, "vul_type": "cwe-125" }
471
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,\n ExceptionInfo *exception)\n{\n char\n page_geometry[MaxTextExtent];", " Image\n *image;", " MagickBooleanType\n logging;", " volatile int\n first_mng_object,\n object_id,\n term_chunk_found,\n skip_to_iend;", " volatile ssize_t\n image_count=0;", " MagickBooleanType\n status;", " MagickOffsetType\n offset;", " MngBox\n default_fb,\n fb,\n previous_fb;", "#if defined(MNG_INSERT_LAYERS)\n PixelPacket\n mng_background_color;\n#endif", " register unsigned char\n *p;", " register ssize_t\n i;", " size_t\n count;", " ssize_t\n loop_level;", " volatile short\n skipping_loop;", "#if defined(MNG_INSERT_LAYERS)\n unsigned int\n mandatory_back=0;\n#endif", " volatile unsigned int\n#ifdef MNG_OBJECT_BUFFERS\n mng_background_object=0,\n#endif\n mng_type=0; /* 0: PNG or JNG; 1: MNG; 2: MNG-LC; 3: MNG-VLC */", " size_t\n default_frame_timeout,\n frame_timeout,\n#if defined(MNG_INSERT_LAYERS)\n image_height,\n image_width,\n#endif\n length;", " /* These delays are all measured in image ticks_per_second,\n * not in MNG ticks_per_second\n */\n volatile size_t\n default_frame_delay,\n final_delay,\n final_image_delay,\n frame_delay,\n#if defined(MNG_INSERT_LAYERS)\n insert_layers,\n#endif\n mng_iterations=1,\n simplicity=0,\n subframe_height=0,\n subframe_width=0;", " previous_fb.top=0;\n previous_fb.bottom=0;\n previous_fb.left=0;\n previous_fb.right=0;\n default_fb.top=0;\n default_fb.bottom=0;\n default_fb.left=0;\n default_fb.right=0;", " logging=LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Enter ReadOneMNGImage()\");", " image=mng_info->image;", " if (LocaleCompare(image_info->magick,\"MNG\") == 0)\n {\n char\n magic_number[MaxTextExtent];", " /* Verify MNG signature. */\n count=(size_t) ReadBlob(image,8,(unsigned char *) magic_number);\n if (memcmp(magic_number,\"\\212MNG\\r\\n\\032\\n\",8) != 0)\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");", " /* Initialize some nonzero members of the MngInfo structure. */\n for (i=0; i < MNG_MAX_OBJECTS; i++)\n {\n mng_info->object_clip[i].right=(ssize_t) PNG_UINT_31_MAX;\n mng_info->object_clip[i].bottom=(ssize_t) PNG_UINT_31_MAX;\n }\n mng_info->exists[0]=MagickTrue;\n }", " skipping_loop=(-1);\n first_mng_object=MagickTrue;\n mng_type=0;\n#if defined(MNG_INSERT_LAYERS)\n insert_layers=MagickFalse; /* should be False when converting or mogrifying */\n#endif\n default_frame_delay=0;\n default_frame_timeout=0;\n frame_delay=0;\n final_delay=1;\n mng_info->ticks_per_second=1UL*image->ticks_per_second;\n object_id=0;\n skip_to_iend=MagickFalse;\n term_chunk_found=MagickFalse;\n mng_info->framing_mode=1;\n#if defined(MNG_INSERT_LAYERS)\n mandatory_back=MagickFalse;\n#endif\n#if defined(MNG_INSERT_LAYERS)\n mng_background_color=image->background_color;\n#endif\n default_fb=mng_info->frame;\n previous_fb=mng_info->frame;\n do\n {\n char\n type[MaxTextExtent];", " if (LocaleCompare(image_info->magick,\"MNG\") == 0)\n {\n unsigned char\n *chunk;", " /*\n Read a new chunk.\n */\n type[0]='\\0';\n (void) ConcatenateMagickString(type,\"errr\",MaxTextExtent);\n length=ReadBlobMSBLong(image);\n count=(size_t) ReadBlob(image,4,(unsigned char *) type);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Reading MNG chunk type %c%c%c%c, length: %.20g\",\n type[0],type[1],type[2],type[3],(double) length);", " if (length > PNG_UINT_31_MAX)\n {\n status=MagickFalse;\n break;\n }", " if (count == 0)\n ThrowReaderException(CorruptImageError,\"CorruptImage\");", " p=NULL;\n chunk=(unsigned char *) NULL;", " if (length != 0)\n {\n chunk=(unsigned char *) AcquireQuantumMemory(length+\n MagickPathExtent,sizeof(*chunk));", " if (chunk == (unsigned char *) NULL)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");", " for (i=0; i < (ssize_t) length; i++)\n {\n int\n c;", " c=ReadBlobByte(image);\n if (c == EOF)\n break;\n chunk[i]=(unsigned char) c;\n }", " p=chunk;\n }", " (void) ReadBlobMSBLong(image); /* read crc word */", "#if !defined(JNG_SUPPORTED)\n if (memcmp(type,mng_JHDR,4) == 0)\n {\n skip_to_iend=MagickTrue;", " if (mng_info->jhdr_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"JNGCompressNotSupported\",\"`%s'\",image->filename);", " mng_info->jhdr_warning++;\n }\n#endif\n if (memcmp(type,mng_DHDR,4) == 0)\n {\n skip_to_iend=MagickTrue;", " if (mng_info->dhdr_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"DeltaPNGNotSupported\",\"`%s'\",image->filename);", " mng_info->dhdr_warning++;\n }\n if (memcmp(type,mng_MEND,4) == 0)\n break;", " if (skip_to_iend)\n {\n if (memcmp(type,mng_IEND,4) == 0)\n skip_to_iend=MagickFalse;", " if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Skip to IEND.\");", " continue;\n }", " if (memcmp(type,mng_MHDR,4) == 0)\n {\n if (length != 28)\n {\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n ThrowReaderException(CorruptImageError,\"CorruptImage\");\n }", " mng_info->mng_width=(size_t) ((p[0] << 24) | (p[1] << 16) |\n (p[2] << 8) | p[3]);", " mng_info->mng_height=(size_t) ((p[4] << 24) | (p[5] << 16) |\n (p[6] << 8) | p[7]);", " if (logging != MagickFalse)\n {\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" MNG width: %.20g\",(double) mng_info->mng_width);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" MNG height: %.20g\",(double) mng_info->mng_height);\n }", " p+=8;\n mng_info->ticks_per_second=(size_t) mng_get_long(p);", " if (mng_info->ticks_per_second == 0)\n default_frame_delay=0;", " else\n default_frame_delay=1UL*image->ticks_per_second/\n mng_info->ticks_per_second;", " frame_delay=default_frame_delay;\n simplicity=0;", " /* Skip nominal layer count, frame count, and play time */\n p+=16;\n simplicity=(size_t) mng_get_long(p);", " mng_type=1; /* Full MNG */", " if ((simplicity != 0) && ((simplicity | 11) == 11))\n mng_type=2; /* LC */", " if ((simplicity != 0) && ((simplicity | 9) == 9))\n mng_type=3; /* VLC */", "#if defined(MNG_INSERT_LAYERS)\n if (mng_type != 3)\n insert_layers=MagickTrue;\n#endif\n if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /* Allocate next image structure. */\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n mng_info->image=image;\n }", " if ((mng_info->mng_width > 65535L) ||\n (mng_info->mng_height > 65535L))\n {\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n ThrowReaderException(ImageError,\"WidthOrHeightExceedsLimit\");\n }", " (void) FormatLocaleString(page_geometry,MaxTextExtent,\n \"%.20gx%.20g+0+0\",(double) mng_info->mng_width,(double)\n mng_info->mng_height);", " mng_info->frame.left=0;\n mng_info->frame.right=(ssize_t) mng_info->mng_width;\n mng_info->frame.top=0;\n mng_info->frame.bottom=(ssize_t) mng_info->mng_height;\n mng_info->clip=default_fb=previous_fb=mng_info->frame;", " for (i=0; i < MNG_MAX_OBJECTS; i++)\n mng_info->object_clip[i]=mng_info->frame;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_TERM,4) == 0)\n {\n int\n repeat=0;", " if (length != 0)\n repeat=p[0];", " if (repeat == 3 && length > 8)\n {\n final_delay=(png_uint_32) mng_get_long(&p[2]);\n mng_iterations=(png_uint_32) mng_get_long(&p[6]);", " if (mng_iterations == PNG_UINT_31_MAX)\n mng_iterations=0;", " image->iterations=mng_iterations;\n term_chunk_found=MagickTrue;\n }", " if (logging != MagickFalse)\n {\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" repeat=%d, final_delay=%.20g, iterations=%.20g\",\n repeat,(double) final_delay, (double) image->iterations);\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_DEFI,4) == 0)\n {\n if (mng_type == 3)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"DEFI chunk found in MNG-VLC datastream\",\"`%s'\",\n image->filename);", " if (length > 1)\n {\n object_id=(p[0] << 8) | p[1];", " if (mng_type == 2 && object_id != 0)\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(),\n CoderError,\"Nonzero object_id in MNG-LC datastream\",\n \"`%s'\", image->filename);", " if (object_id > MNG_MAX_OBJECTS)\n {\n /*\n Instead of using a warning we should allocate a larger\n MngInfo structure and continue.\n */\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(), CoderError,\n \"object id too large\",\"`%s'\",image->filename);\n object_id=MNG_MAX_OBJECTS;\n }", " if (mng_info->exists[object_id])\n if (mng_info->frozen[object_id])\n {\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(),CoderError,\n \"DEFI cannot redefine a frozen MNG object\",\"`%s'\",\n image->filename);\n continue;\n }", " mng_info->exists[object_id]=MagickTrue;", " if (length > 2)\n mng_info->invisible[object_id]=p[2];", " /*\n Extract object offset info.\n */\n if (length > 11)\n {\n mng_info->x_off[object_id]=(ssize_t) ((p[4] << 24) |\n (p[5] << 16) | (p[6] << 8) | p[7]);", " mng_info->y_off[object_id]=(ssize_t) ((p[8] << 24) |\n (p[9] << 16) | (p[10] << 8) | p[11]);", " if (logging != MagickFalse)\n {\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" x_off[%d]: %.20g, y_off[%d]: %.20g\",\n object_id,(double) mng_info->x_off[object_id],\n object_id,(double) mng_info->y_off[object_id]);\n }\n }", " /*\n Extract object clipping info.\n */\n \n if (length > 27)\n mng_info->object_clip[object_id]=\n mng_read_box(mng_info->frame,0, &p[12]);\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_bKGD,4) == 0)\n {\n mng_info->have_global_bkgd=MagickFalse;", " if (length > 5)\n {\n mng_info->mng_global_bkgd.red=\n ScaleShortToQuantum((unsigned short) ((p[0] << 8) | p[1]));", " mng_info->mng_global_bkgd.green=\n ScaleShortToQuantum((unsigned short) ((p[2] << 8) | p[3]));", " mng_info->mng_global_bkgd.blue=\n ScaleShortToQuantum((unsigned short) ((p[4] << 8) | p[5]));", " mng_info->have_global_bkgd=MagickTrue;\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_BACK,4) == 0)\n {\n#if defined(MNG_INSERT_LAYERS)\n if (length > 6)\n mandatory_back=p[6];", " else\n mandatory_back=0;", " if (mandatory_back && length > 5)\n {\n mng_background_color.red=\n ScaleShortToQuantum((unsigned short) ((p[0] << 8) | p[1]));", " mng_background_color.green=\n ScaleShortToQuantum((unsigned short) ((p[2] << 8) | p[3]));", " mng_background_color.blue=\n ScaleShortToQuantum((unsigned short) ((p[4] << 8) | p[5]));", " mng_background_color.opacity=OpaqueOpacity;\n }", "#ifdef MNG_OBJECT_BUFFERS\n if (length > 8)\n mng_background_object=(p[7] << 8) | p[8];\n#endif\n#endif\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_PLTE,4) == 0)\n {\n /* Read global PLTE. */", " if (length && (length < 769))\n {\n if (mng_info->global_plte == (png_colorp) NULL)\n mng_info->global_plte=(png_colorp) AcquireQuantumMemory(256,\n sizeof(*mng_info->global_plte));", " for (i=0; i < (ssize_t) (length/3); i++)\n {\n mng_info->global_plte[i].red=p[3*i];\n mng_info->global_plte[i].green=p[3*i+1];\n mng_info->global_plte[i].blue=p[3*i+2];\n }", " mng_info->global_plte_length=(unsigned int) (length/3);\n }\n#ifdef MNG_LOOSE\n for ( ; i < 256; i++)\n {\n mng_info->global_plte[i].red=i;\n mng_info->global_plte[i].green=i;\n mng_info->global_plte[i].blue=i;\n }", " if (length != 0)\n mng_info->global_plte_length=256;\n#endif\n else\n mng_info->global_plte_length=0;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_tRNS,4) == 0)\n {\n /* read global tRNS */", " if (length > 0 && length < 257)\n for (i=0; i < (ssize_t) length; i++)\n mng_info->global_trns[i]=p[i];", "#ifdef MNG_LOOSE\n for ( ; i < 256; i++)\n mng_info->global_trns[i]=255;\n#endif\n mng_info->global_trns_length=(unsigned int) length;\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_gAMA,4) == 0)\n {\n if (length == 4)\n {\n ssize_t\n igamma;", " igamma=mng_get_long(p);\n mng_info->global_gamma=((float) igamma)*0.00001;\n mng_info->have_global_gama=MagickTrue;\n }", " else\n mng_info->have_global_gama=MagickFalse;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_cHRM,4) == 0)\n {\n /* Read global cHRM */", " if (length == 32)\n {\n mng_info->global_chrm.white_point.x=0.00001*mng_get_long(p);\n mng_info->global_chrm.white_point.y=0.00001*mng_get_long(&p[4]);\n mng_info->global_chrm.red_primary.x=0.00001*mng_get_long(&p[8]);\n mng_info->global_chrm.red_primary.y=0.00001*\n mng_get_long(&p[12]);\n mng_info->global_chrm.green_primary.x=0.00001*\n mng_get_long(&p[16]);\n mng_info->global_chrm.green_primary.y=0.00001*\n mng_get_long(&p[20]);\n mng_info->global_chrm.blue_primary.x=0.00001*\n mng_get_long(&p[24]);\n mng_info->global_chrm.blue_primary.y=0.00001*\n mng_get_long(&p[28]);\n mng_info->have_global_chrm=MagickTrue;\n }\n else\n mng_info->have_global_chrm=MagickFalse;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_sRGB,4) == 0)\n {\n /*\n Read global sRGB.\n */\n if (length != 0)\n {\n mng_info->global_srgb_intent=\n Magick_RenderingIntent_from_PNG_RenderingIntent(p[0]);\n mng_info->have_global_srgb=MagickTrue;\n }\n else\n mng_info->have_global_srgb=MagickFalse;", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_iCCP,4) == 0)\n {\n /* To do: */", " /*\n Read global iCCP.\n */\n if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " continue;\n }", " if (memcmp(type,mng_FRAM,4) == 0)\n {\n if (mng_type == 3)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"FRAM chunk found in MNG-VLC datastream\",\"`%s'\",\n image->filename);", " if ((mng_info->framing_mode == 2) || (mng_info->framing_mode == 4))\n image->delay=frame_delay;", " frame_delay=default_frame_delay;\n frame_timeout=default_frame_timeout;\n fb=default_fb;", " if (length > 0)\n if (p[0])\n mng_info->framing_mode=p[0];", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Framing_mode=%d\",mng_info->framing_mode);", " if (length > 6)\n {\n /* Note the delay and frame clipping boundaries. */", " p++; /* framing mode */", " while (*p && ((p-chunk) < (ssize_t) length))\n p++; /* frame name */", " p++; /* frame name terminator */", " if ((p-chunk) < (ssize_t) (length-4))\n {\n int\n change_delay,\n change_timeout,\n change_clipping;", " change_delay=(*p++);\n change_timeout=(*p++);\n change_clipping=(*p++);\n p++; /* change_sync */", " if (change_delay && (p-chunk) < (ssize_t) (length-4))\n {\n frame_delay=1UL*image->ticks_per_second*\n mng_get_long(p);", " if (mng_info->ticks_per_second != 0)\n frame_delay/=mng_info->ticks_per_second;", " else\n frame_delay=PNG_UINT_31_MAX;", " if (change_delay == 2)\n default_frame_delay=frame_delay;", " p+=4;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Framing_delay=%.20g\",(double) frame_delay);\n }", " if (change_timeout && (p-chunk) < (ssize_t) (length-4))\n {\n frame_timeout=1UL*image->ticks_per_second*\n mng_get_long(p);", " if (mng_info->ticks_per_second != 0)\n frame_timeout/=mng_info->ticks_per_second;", " else\n frame_timeout=PNG_UINT_31_MAX;", " if (change_timeout == 2)\n default_frame_timeout=frame_timeout;", " p+=4;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Framing_timeout=%.20g\",(double) frame_timeout);\n }", " if (change_clipping && (p-chunk) < (ssize_t) (length-17))\n {\n fb=mng_read_box(previous_fb,(char) p[0],&p[1]);\n p+=17;\n previous_fb=fb;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Frame_clip: L=%.20g R=%.20g T=%.20g B=%.20g\",\n (double) fb.left,(double) fb.right,(double) fb.top,\n (double) fb.bottom);", " if (change_clipping == 2)\n default_fb=fb;\n }\n }\n }\n mng_info->clip=fb;\n mng_info->clip=mng_minimum_box(fb,mng_info->frame);", " subframe_width=(size_t) (mng_info->clip.right\n -mng_info->clip.left);", " subframe_height=(size_t) (mng_info->clip.bottom\n -mng_info->clip.top);\n /*\n Insert a background layer behind the frame if framing_mode is 4.\n */\n#if defined(MNG_INSERT_LAYERS)\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" subframe_width=%.20g, subframe_height=%.20g\",(double)\n subframe_width,(double) subframe_height);", " if (insert_layers && (mng_info->framing_mode == 4) &&\n (subframe_width) && (subframe_height))\n {\n /* Allocate next image structure. */\n if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n }", " mng_info->image=image;", " if (term_chunk_found)\n {\n image->start_loop=MagickTrue;\n image->iterations=mng_iterations;\n term_chunk_found=MagickFalse;\n }", " else\n image->start_loop=MagickFalse;", " image->columns=subframe_width;\n image->rows=subframe_height;\n image->page.width=subframe_width;\n image->page.height=subframe_height;\n image->page.x=mng_info->clip.left;\n image->page.y=mng_info->clip.top;\n image->background_color=mng_background_color;\n image->matte=MagickFalse;\n image->delay=0;\n (void) SetImageBackgroundColor(image);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Insert backgd layer, L=%.20g, R=%.20g T=%.20g, B=%.20g\",\n (double) mng_info->clip.left,(double) mng_info->clip.right,\n (double) mng_info->clip.top,(double) mng_info->clip.bottom);\n }\n#endif\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_CLIP,4) == 0)\n {\n unsigned int\n first_object,\n last_object;", " /*\n Read CLIP.\n */\n if (length > 3)\n {\n first_object=(p[0] << 8) | p[1];\n last_object=(p[2] << 8) | p[3];\n p+=4;", " for (i=(int) first_object; i <= (int) last_object; i++)\n {\n if (mng_info->exists[i] && !mng_info->frozen[i])\n {\n MngBox\n box;", " box=mng_info->object_clip[i];\n if ((p-chunk) < (ssize_t) (length-17))\n mng_info->object_clip[i]=\n mng_read_box(box,(char) p[0],&p[1]);\n }\n }", " }\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n if (memcmp(type,mng_SAVE,4) == 0)\n {\n for (i=1; i < MNG_MAX_OBJECTS; i++)\n if (mng_info->exists[i])\n {\n mng_info->frozen[i]=MagickTrue;\n#ifdef MNG_OBJECT_BUFFERS\n if (mng_info->ob[i] != (MngBuffer *) NULL)\n mng_info->ob[i]->frozen=MagickTrue;\n#endif\n }", " if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " continue;\n }", " if ((memcmp(type,mng_DISC,4) == 0) || (memcmp(type,mng_SEEK,4) == 0))\n {\n /* Read DISC or SEEK. */", " if ((length == 0) || !memcmp(type,mng_SEEK,4))\n {\n for (i=1; i < MNG_MAX_OBJECTS; i++)\n MngInfoDiscardObject(mng_info,i);\n }", " else\n {\n register ssize_t\n j;", " for (j=1; j < (ssize_t) length; j+=2)\n {\n i=p[j-1] << 8 | p[j];\n MngInfoDiscardObject(mng_info,i);\n }\n }", " if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " continue;\n }", " if (memcmp(type,mng_MOVE,4) == 0)\n {\n size_t\n first_object,\n last_object;", " /* read MOVE */", " if (length > 3)\n {\n first_object=(p[0] << 8) | p[1];\n last_object=(p[2] << 8) | p[3];\n p+=4;", " for (i=(ssize_t) first_object; i <= (ssize_t) last_object; i++)\n {", " if ((i < 0) || (i >= MNG_MAX_OBJECTS))\n continue;", " if (mng_info->exists[i] && !mng_info->frozen[i] &&\n (p-chunk) < (ssize_t) (length-8))\n {\n MngPair\n new_pair;", " MngPair\n old_pair;", " old_pair.a=mng_info->x_off[i];\n old_pair.b=mng_info->y_off[i];\n new_pair=mng_read_pair(old_pair,(int) p[0],&p[1]);\n mng_info->x_off[i]=new_pair.a;\n mng_info->y_off[i]=new_pair.b;\n }\n }\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_LOOP,4) == 0)\n {\n ssize_t loop_iters=1;\n if (length > 4)\n {\n loop_level=chunk[0];\n mng_info->loop_active[loop_level]=1; /* mark loop active */", " /* Record starting point. */\n loop_iters=mng_get_long(&chunk[1]);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" LOOP level %.20g has %.20g iterations \",\n (double) loop_level, (double) loop_iters);", " if (loop_iters == 0)\n skipping_loop=loop_level;", " else\n {\n mng_info->loop_jump[loop_level]=TellBlob(image);\n mng_info->loop_count[loop_level]=loop_iters;\n }", " mng_info->loop_iteration[loop_level]=0;\n }\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_ENDL,4) == 0)\n {\n if (length > 0)\n {\n loop_level=chunk[0];", " if (skipping_loop > 0)\n {\n if (skipping_loop == loop_level)\n {\n /*\n Found end of zero-iteration loop.\n */\n skipping_loop=(-1);\n mng_info->loop_active[loop_level]=0;\n }\n }", " else\n {\n if (mng_info->loop_active[loop_level] == 1)\n {\n mng_info->loop_count[loop_level]--;\n mng_info->loop_iteration[loop_level]++;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" ENDL: LOOP level %.20g has %.20g remaining iters \",\n (double) loop_level,(double)\n mng_info->loop_count[loop_level]);", " if (mng_info->loop_count[loop_level] != 0)\n {\n offset=SeekBlob(image,\n mng_info->loop_jump[loop_level], SEEK_SET);", " if (offset < 0)\n {\n chunk=(unsigned char *) RelinquishMagickMemory(\n chunk);\n ThrowReaderException(CorruptImageError,\n \"ImproperImageHeader\");\n }\n }", " else\n {\n short\n last_level;", " /*\n Finished loop.\n */\n mng_info->loop_active[loop_level]=0;\n last_level=(-1);\n for (i=0; i < loop_level; i++)\n if (mng_info->loop_active[i] == 1)\n last_level=(short) i;\n loop_level=last_level;\n }\n }\n }\n }", " chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_CLON,4) == 0)\n {\n if (mng_info->clon_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"CLON is not implemented yet\",\"`%s'\",\n image->filename);", " mng_info->clon_warning++;\n }", " if (memcmp(type,mng_MAGN,4) == 0)\n {\n png_uint_16\n magn_first,\n magn_last,\n magn_mb,\n magn_ml,\n magn_mr,\n magn_mt,\n magn_mx,\n magn_my,\n magn_methx,\n magn_methy;", " if (length > 1)\n magn_first=(p[0] << 8) | p[1];", " else\n magn_first=0;", " if (length > 3)\n magn_last=(p[2] << 8) | p[3];", " else\n magn_last=magn_first;\n#ifndef MNG_OBJECT_BUFFERS\n if (magn_first || magn_last)\n if (mng_info->magn_warning == 0)\n {\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(),CoderError,\n \"MAGN is not implemented yet for nonzero objects\",\n \"`%s'\",image->filename);", " mng_info->magn_warning++;\n }\n#endif\n if (length > 4)\n magn_methx=p[4];", " else\n magn_methx=0;", " if (length > 6)\n magn_mx=(p[5] << 8) | p[6];", " else\n magn_mx=1;", " if (magn_mx == 0)\n magn_mx=1;", " if (length > 8)\n magn_my=(p[7] << 8) | p[8];", " else\n magn_my=magn_mx;", " if (magn_my == 0)\n magn_my=1;", " if (length > 10)\n magn_ml=(p[9] << 8) | p[10];", " else\n magn_ml=magn_mx;", " if (magn_ml == 0)\n magn_ml=1;", " if (length > 12)\n magn_mr=(p[11] << 8) | p[12];", " else\n magn_mr=magn_mx;", " if (magn_mr == 0)\n magn_mr=1;", " if (length > 14)\n magn_mt=(p[13] << 8) | p[14];", " else\n magn_mt=magn_my;", " if (magn_mt == 0)\n magn_mt=1;", " if (length > 16)\n magn_mb=(p[15] << 8) | p[16];", " else\n magn_mb=magn_my;", " if (magn_mb == 0)\n magn_mb=1;", " if (length > 17)\n magn_methy=p[17];", " else\n magn_methy=magn_methx;", "\n if (magn_methx > 5 || magn_methy > 5)\n if (mng_info->magn_warning == 0)\n {\n (void) ThrowMagickException(&image->exception,\n GetMagickModule(),CoderError,\n \"Unknown MAGN method in MNG datastream\",\"`%s'\",\n image->filename);", " mng_info->magn_warning++;\n }\n#ifdef MNG_OBJECT_BUFFERS\n /* Magnify existing objects in the range magn_first to magn_last */\n#endif\n if (magn_first == 0 || magn_last == 0)\n {\n /* Save the magnification factors for object 0 */\n mng_info->magn_mb=magn_mb;\n mng_info->magn_ml=magn_ml;\n mng_info->magn_mr=magn_mr;\n mng_info->magn_mt=magn_mt;\n mng_info->magn_mx=magn_mx;\n mng_info->magn_my=magn_my;\n mng_info->magn_methx=magn_methx;\n mng_info->magn_methy=magn_methy;\n }\n }", " if (memcmp(type,mng_PAST,4) == 0)\n {\n if (mng_info->past_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"PAST is not implemented yet\",\"`%s'\",\n image->filename);", " mng_info->past_warning++;\n }", " if (memcmp(type,mng_SHOW,4) == 0)\n {\n if (mng_info->show_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"SHOW is not implemented yet\",\"`%s'\",\n image->filename);", " mng_info->show_warning++;\n }", " if (memcmp(type,mng_sBIT,4) == 0)\n {\n if (length < 4)\n mng_info->have_global_sbit=MagickFalse;", " else\n {\n mng_info->global_sbit.gray=p[0];\n mng_info->global_sbit.red=p[0];\n mng_info->global_sbit.green=p[1];\n mng_info->global_sbit.blue=p[2];\n mng_info->global_sbit.alpha=p[3];\n mng_info->have_global_sbit=MagickTrue;\n }\n }\n if (memcmp(type,mng_pHYs,4) == 0)\n {\n if (length > 8)\n {\n mng_info->global_x_pixels_per_unit=\n (size_t) mng_get_long(p);\n mng_info->global_y_pixels_per_unit=\n (size_t) mng_get_long(&p[4]);\n mng_info->global_phys_unit_type=p[8];\n mng_info->have_global_phys=MagickTrue;\n }", " else\n mng_info->have_global_phys=MagickFalse;\n }\n if (memcmp(type,mng_pHYg,4) == 0)\n {\n if (mng_info->phyg_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"pHYg is not implemented.\",\"`%s'\",image->filename);", " mng_info->phyg_warning++;\n }\n if (memcmp(type,mng_BASI,4) == 0)\n {\n skip_to_iend=MagickTrue;", " if (mng_info->basi_warning == 0)\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"BASI is not implemented yet\",\"`%s'\",\n image->filename);", " mng_info->basi_warning++;\n#ifdef MNG_BASI_SUPPORTED\n if (length > 11)\n {\n basi_width=(size_t) ((p[0] << 24) | (p[1] << 16) |\n (p[2] << 8) | p[3]);\n basi_height=(size_t) ((p[4] << 24) | (p[5] << 16) |\n (p[6] << 8) | p[7]);\n basi_color_type=p[8];\n basi_compression_method=p[9];\n basi_filter_type=p[10];\n basi_interlace_method=p[11];\n }\n if (length > 13)\n basi_red=(p[12] << 8) & p[13];", " else\n basi_red=0;", " if (length > 15)\n basi_green=(p[14] << 8) & p[15];", " else\n basi_green=0;", " if (length > 17)\n basi_blue=(p[16] << 8) & p[17];", " else\n basi_blue=0;", " if (length > 19)\n basi_alpha=(p[18] << 8) & p[19];", " else\n {\n if (basi_sample_depth == 16)\n basi_alpha=65535L;\n else\n basi_alpha=255;\n }", " if (length > 20)\n basi_viewable=p[20];", " else\n basi_viewable=0;", "#endif\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }", " if (memcmp(type,mng_IHDR,4)\n#if defined(JNG_SUPPORTED)\n && memcmp(type,mng_JHDR,4)\n#endif\n )\n {\n /* Not an IHDR or JHDR chunk */\n if (length != 0)\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " continue;\n }\n/* Process IHDR */\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Processing %c%c%c%c chunk\",type[0],type[1],type[2],type[3]);", " mng_info->exists[object_id]=MagickTrue;\n mng_info->viewable[object_id]=MagickTrue;", " if (mng_info->invisible[object_id])\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Skipping invisible object\");", " skip_to_iend=MagickTrue;\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n continue;\n }\n#if defined(MNG_INSERT_LAYERS)\n if (length < 8)\n {\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n }", " image_width=(size_t) mng_get_long(p);\n image_height=(size_t) mng_get_long(&p[4]);\n#endif\n chunk=(unsigned char *) RelinquishMagickMemory(chunk);", " /*\n Insert a transparent background layer behind the entire animation\n if it is not full screen.\n */\n#if defined(MNG_INSERT_LAYERS)\n if (insert_layers && mng_type && first_mng_object)\n {\n if ((mng_info->clip.left > 0) || (mng_info->clip.top > 0) ||\n (image_width < mng_info->mng_width) ||\n (mng_info->clip.right < (ssize_t) mng_info->mng_width) ||\n (image_height < mng_info->mng_height) ||\n (mng_info->clip.bottom < (ssize_t) mng_info->mng_height))\n {\n if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n }\n mng_info->image=image;", " if (term_chunk_found)\n {\n image->start_loop=MagickTrue;\n image->iterations=mng_iterations;\n term_chunk_found=MagickFalse;\n }", " else\n image->start_loop=MagickFalse;", " /* Make a background rectangle. */", " image->delay=0;\n image->columns=mng_info->mng_width;\n image->rows=mng_info->mng_height;\n image->page.width=mng_info->mng_width;\n image->page.height=mng_info->mng_height;\n image->page.x=0;\n image->page.y=0;\n image->background_color=mng_background_color;\n (void) SetImageBackgroundColor(image);\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Inserted transparent background layer, W=%.20g, H=%.20g\",\n (double) mng_info->mng_width,(double) mng_info->mng_height);\n }\n }\n /*\n Insert a background layer behind the upcoming image if\n framing_mode is 3, and we haven't already inserted one.\n */\n if (insert_layers && (mng_info->framing_mode == 3) &&\n (subframe_width) && (subframe_height) && (simplicity == 0 ||\n (simplicity & 0x08)))\n {\n if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n }", " mng_info->image=image;", " if (term_chunk_found)\n {\n image->start_loop=MagickTrue;\n image->iterations=mng_iterations;\n term_chunk_found=MagickFalse;\n }", " else\n image->start_loop=MagickFalse;", " image->delay=0;\n image->columns=subframe_width;\n image->rows=subframe_height;\n image->page.width=subframe_width;\n image->page.height=subframe_height;\n image->page.x=mng_info->clip.left;\n image->page.y=mng_info->clip.top;\n image->background_color=mng_background_color;\n image->matte=MagickFalse;\n (void) SetImageBackgroundColor(image);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Insert background layer, L=%.20g, R=%.20g T=%.20g, B=%.20g\",\n (double) mng_info->clip.left,(double) mng_info->clip.right,\n (double) mng_info->clip.top,(double) mng_info->clip.bottom);\n }\n#endif /* MNG_INSERT_LAYERS */\n first_mng_object=MagickFalse;", " if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " image=SyncNextImageInList(image);\n }\n mng_info->image=image;\n status=SetImageProgress(image,LoadImagesTag,TellBlob(image),\n GetBlobSize(image));", " if (status == MagickFalse)\n break;", " if (term_chunk_found)\n {\n image->start_loop=MagickTrue;\n term_chunk_found=MagickFalse;\n }", " else\n image->start_loop=MagickFalse;", " if (mng_info->framing_mode == 1 || mng_info->framing_mode == 3)\n {\n image->delay=frame_delay;\n frame_delay=default_frame_delay;\n }", " else\n image->delay=0;", " image->page.width=mng_info->mng_width;\n image->page.height=mng_info->mng_height;\n image->page.x=mng_info->x_off[object_id];\n image->page.y=mng_info->y_off[object_id];\n image->iterations=mng_iterations;", " /*\n Seek back to the beginning of the IHDR or JHDR chunk's length field.\n */", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Seeking back to beginning of %c%c%c%c chunk\",type[0],type[1],\n type[2],type[3]);", " offset=SeekBlob(image,-((ssize_t) length+12),SEEK_CUR);", " if (offset < 0)\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n }", " mng_info->image=image;\n mng_info->mng_type=mng_type;\n mng_info->object_id=object_id;", " if (memcmp(type,mng_IHDR,4) == 0)\n image=ReadOnePNGImage(mng_info,image_info,exception);", "#if defined(JNG_SUPPORTED)\n else\n image=ReadOneJNGImage(mng_info,image_info,exception);\n#endif", " if (image == (Image *) NULL)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \"exit ReadJNGImage() with error\");", " return((Image *) NULL);\n }", " if (image->columns == 0 || image->rows == 0)\n {\n (void) CloseBlob(image);\n return(DestroyImageList(image));\n }", " mng_info->image=image;", " if (mng_type)\n {\n MngBox\n crop_box;", " if (mng_info->magn_methx || mng_info->magn_methy)\n {\n png_uint_32\n magnified_height,\n magnified_width;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Processing MNG MAGN chunk\");", " if (mng_info->magn_methx == 1)\n {\n magnified_width=mng_info->magn_ml;", " if (image->columns > 1)\n magnified_width += mng_info->magn_mr;", " if (image->columns > 2)\n magnified_width += (png_uint_32)\n ((image->columns-2)*(mng_info->magn_mx));\n }", " else\n {\n magnified_width=(png_uint_32) image->columns;", " if (image->columns > 1)\n magnified_width += mng_info->magn_ml-1;", " if (image->columns > 2)\n magnified_width += mng_info->magn_mr-1;", " if (image->columns > 3)\n magnified_width += (png_uint_32)\n ((image->columns-3)*(mng_info->magn_mx-1));\n }", " if (mng_info->magn_methy == 1)\n {\n magnified_height=mng_info->magn_mt;", " if (image->rows > 1)\n magnified_height += mng_info->magn_mb;", " if (image->rows > 2)\n magnified_height += (png_uint_32)\n ((image->rows-2)*(mng_info->magn_my));\n }", " else\n {\n magnified_height=(png_uint_32) image->rows;", " if (image->rows > 1)\n magnified_height += mng_info->magn_mt-1;", " if (image->rows > 2)\n magnified_height += mng_info->magn_mb-1;", " if (image->rows > 3)\n magnified_height += (png_uint_32)\n ((image->rows-3)*(mng_info->magn_my-1));\n }", " if (magnified_height > image->rows ||\n magnified_width > image->columns)\n {\n Image\n *large_image;", " int\n yy;", " ssize_t\n m,\n y;", " register ssize_t\n x;", " register PixelPacket\n *n,\n *q;", " PixelPacket\n *next,\n *prev;", " png_uint_16\n magn_methx,\n magn_methy;", " /* Allocate next image structure. */", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Allocate magnified image\");", " AcquireNextImage(image_info,image);", " if (GetNextImageInList(image) == (Image *) NULL)\n return(DestroyImageList(image));", " large_image=SyncNextImageInList(image);", " large_image->columns=magnified_width;\n large_image->rows=magnified_height;", " magn_methx=mng_info->magn_methx;\n magn_methy=mng_info->magn_methy;", "#if (MAGICKCORE_QUANTUM_DEPTH > 16)\n#define QM unsigned short\n if (magn_methx != 1 || magn_methy != 1)\n {\n /*\n Scale pixels to unsigned shorts to prevent\n overflow of intermediate values of interpolations\n */\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=GetAuthenticPixels(image,0,y,image->columns,1,\n exception);", " for (x=(ssize_t) image->columns-1; x >= 0; x--)\n {\n SetPixelRed(q,ScaleQuantumToShort(\n GetPixelRed(q)));\n SetPixelGreen(q,ScaleQuantumToShort(\n GetPixelGreen(q)));\n SetPixelBlue(q,ScaleQuantumToShort(\n GetPixelBlue(q)));\n SetPixelOpacity(q,ScaleQuantumToShort(\n GetPixelOpacity(q)));\n q++;\n }", " if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n }\n }\n#else\n#define QM Quantum\n#endif", " if (image->matte != MagickFalse)\n (void) SetImageBackgroundColor(large_image);", " else\n {\n large_image->background_color.opacity=OpaqueOpacity;\n (void) SetImageBackgroundColor(large_image);", " if (magn_methx == 4)\n magn_methx=2;", " if (magn_methx == 5)\n magn_methx=3;", " if (magn_methy == 4)\n magn_methy=2;", " if (magn_methy == 5)\n magn_methy=3;\n }", " /* magnify the rows into the right side of the large image */", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Magnify the rows to %.20g\",(double) large_image->rows);\n m=(ssize_t) mng_info->magn_mt;\n yy=0;\n length=(size_t) image->columns;\n next=(PixelPacket *) AcquireQuantumMemory(length,sizeof(*next));\n prev=(PixelPacket *) AcquireQuantumMemory(length,sizeof(*prev));", " if ((prev == (PixelPacket *) NULL) ||\n (next == (PixelPacket *) NULL))\n {\n image=DestroyImageList(image);\n ThrowReaderException(ResourceLimitError,\n \"MemoryAllocationFailed\");\n }", " n=GetAuthenticPixels(image,0,0,image->columns,1,exception);\n (void) CopyMagickMemory(next,n,length);", " for (y=0; y < (ssize_t) image->rows; y++)\n {\n if (y == 0)\n m=(ssize_t) mng_info->magn_mt;", " else if (magn_methy > 1 && y == (ssize_t) image->rows-2)\n m=(ssize_t) mng_info->magn_mb;", " else if (magn_methy <= 1 && y == (ssize_t) image->rows-1)\n m=(ssize_t) mng_info->magn_mb;", " else if (magn_methy > 1 && y == (ssize_t) image->rows-1)\n m=1;", " else\n m=(ssize_t) mng_info->magn_my;", " n=prev;\n prev=next;\n next=n;", " if (y < (ssize_t) image->rows-1)\n {\n n=GetAuthenticPixels(image,0,y+1,image->columns,1,\n exception);\n (void) CopyMagickMemory(next,n,length);\n }", " for (i=0; i < m; i++, yy++)\n {\n register PixelPacket\n *pixels;", " assert(yy < (ssize_t) large_image->rows);\n pixels=prev;\n n=next;\n q=GetAuthenticPixels(large_image,0,yy,large_image->columns,\n 1,exception);\n q+=(large_image->columns-image->columns);", " for (x=(ssize_t) image->columns-1; x >= 0; x--)\n {\n /* To do: get color as function of indexes[x] */\n /*\n if (image->storage_class == PseudoClass)\n {\n }\n */", " if (magn_methy <= 1)\n {\n /* replicate previous */\n SetPixelRGBO(q,(pixels));\n }", " else if (magn_methy == 2 || magn_methy == 4)\n {\n if (i == 0)\n {\n SetPixelRGBO(q,(pixels));\n }", " else\n {\n /* Interpolate */\n SetPixelRed(q,\n ((QM) (((ssize_t)\n (2*i*(GetPixelRed(n)\n -GetPixelRed(pixels)+m))/\n ((ssize_t) (m*2))\n +GetPixelRed(pixels)))));\n SetPixelGreen(q,\n ((QM) (((ssize_t)\n (2*i*(GetPixelGreen(n)\n -GetPixelGreen(pixels)+m))/\n ((ssize_t) (m*2))\n +GetPixelGreen(pixels)))));\n SetPixelBlue(q,\n ((QM) (((ssize_t)\n (2*i*(GetPixelBlue(n)\n -GetPixelBlue(pixels)+m))/\n ((ssize_t) (m*2))\n +GetPixelBlue(pixels)))));", " if (image->matte != MagickFalse)\n SetPixelOpacity(q,\n ((QM) (((ssize_t)\n (2*i*(GetPixelOpacity(n)\n -GetPixelOpacity(pixels)+m))\n /((ssize_t) (m*2))+\n GetPixelOpacity(pixels)))));\n }", " if (magn_methy == 4)\n {\n /* Replicate nearest */\n if (i <= ((m+1) << 1))\n SetPixelOpacity(q,\n (*pixels).opacity+0);\n else\n SetPixelOpacity(q,\n (*n).opacity+0);\n }\n }", " else /* if (magn_methy == 3 || magn_methy == 5) */\n {\n /* Replicate nearest */\n if (i <= ((m+1) << 1))\n {\n SetPixelRGBO(q,(pixels));\n }", " else\n {\n SetPixelRGBO(q,(n));\n }", " if (magn_methy == 5)\n {\n SetPixelOpacity(q,\n (QM) (((ssize_t) (2*i*\n (GetPixelOpacity(n)\n -GetPixelOpacity(pixels))\n +m))/((ssize_t) (m*2))\n +GetPixelOpacity(pixels)));\n }\n }\n n++;\n q++;\n pixels++;\n } /* x */", " if (SyncAuthenticPixels(large_image,exception) == 0)\n break;", " } /* i */\n } /* y */", " prev=(PixelPacket *) RelinquishMagickMemory(prev);\n next=(PixelPacket *) RelinquishMagickMemory(next);", " length=image->columns;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Delete original image\");", " DeleteImageFromList(&image);", " image=large_image;", " mng_info->image=image;", " /* magnify the columns */\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Magnify the columns to %.20g\",(double) image->columns);", " for (y=0; y < (ssize_t) image->rows; y++)\n {\n register PixelPacket\n *pixels;", " q=GetAuthenticPixels(image,0,y,image->columns,1,exception);\n pixels=q+(image->columns-length);\n n=pixels+1;", " for (x=(ssize_t) (image->columns-length);\n x < (ssize_t) image->columns; x++)\n {\n /* To do: Rewrite using Get/Set***PixelComponent() */", " if (x == (ssize_t) (image->columns-length))\n m=(ssize_t) mng_info->magn_ml;", " else if (magn_methx > 1 && x == (ssize_t) image->columns-2)\n m=(ssize_t) mng_info->magn_mr;", " else if (magn_methx <= 1 && x == (ssize_t) image->columns-1)\n m=(ssize_t) mng_info->magn_mr;", " else if (magn_methx > 1 && x == (ssize_t) image->columns-1)\n m=1;", " else\n m=(ssize_t) mng_info->magn_mx;", " for (i=0; i < m; i++)\n {\n if (magn_methx <= 1)\n {\n /* replicate previous */\n SetPixelRGBO(q,(pixels));\n }", " else if (magn_methx == 2 || magn_methx == 4)\n {\n if (i == 0)\n {\n SetPixelRGBO(q,(pixels));\n }", " /* To do: Rewrite using Get/Set***PixelComponent() */\n else\n {\n /* Interpolate */\n SetPixelRed(q,\n (QM) ((2*i*(\n GetPixelRed(n)\n -GetPixelRed(pixels))+m)\n /((ssize_t) (m*2))+\n GetPixelRed(pixels)));", " SetPixelGreen(q,\n (QM) ((2*i*(\n GetPixelGreen(n)\n -GetPixelGreen(pixels))+m)\n /((ssize_t) (m*2))+\n GetPixelGreen(pixels)));", " SetPixelBlue(q,\n (QM) ((2*i*(\n GetPixelBlue(n)\n -GetPixelBlue(pixels))+m)\n /((ssize_t) (m*2))+\n GetPixelBlue(pixels)));\n if (image->matte != MagickFalse)\n SetPixelOpacity(q,\n (QM) ((2*i*(\n GetPixelOpacity(n)\n -GetPixelOpacity(pixels))+m)\n /((ssize_t) (m*2))+\n GetPixelOpacity(pixels)));\n }", " if (magn_methx == 4)\n {\n /* Replicate nearest */\n if (i <= ((m+1) << 1))\n {\n SetPixelOpacity(q,\n GetPixelOpacity(pixels)+0);\n }\n else\n {\n SetPixelOpacity(q,\n GetPixelOpacity(n)+0);\n }\n }\n }", " else /* if (magn_methx == 3 || magn_methx == 5) */\n {\n /* Replicate nearest */\n if (i <= ((m+1) << 1))\n {\n SetPixelRGBO(q,(pixels));\n }", " else\n {\n SetPixelRGBO(q,(n));\n }", " if (magn_methx == 5)\n {\n /* Interpolate */\n SetPixelOpacity(q,\n (QM) ((2*i*( GetPixelOpacity(n)\n -GetPixelOpacity(pixels))+m)/\n ((ssize_t) (m*2))\n +GetPixelOpacity(pixels)));\n }\n }\n q++;\n }\n n++;\n }", " if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n }\n#if (MAGICKCORE_QUANTUM_DEPTH > 16)\n if (magn_methx != 1 || magn_methy != 1)\n {\n /*\n Rescale pixels to Quantum\n */\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n q=GetAuthenticPixels(image,0,y,image->columns,1,exception);", " for (x=(ssize_t) image->columns-1; x >= 0; x--)\n {\n SetPixelRed(q,ScaleShortToQuantum(\n GetPixelRed(q)));\n SetPixelGreen(q,ScaleShortToQuantum(\n GetPixelGreen(q)));\n SetPixelBlue(q,ScaleShortToQuantum(\n GetPixelBlue(q)));\n SetPixelOpacity(q,ScaleShortToQuantum(\n GetPixelOpacity(q)));\n q++;\n }", " if (SyncAuthenticPixels(image,exception) == MagickFalse)\n break;\n }\n }\n#endif\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Finished MAGN processing\");\n }\n }", " /*\n Crop_box is with respect to the upper left corner of the MNG.\n */\n crop_box.left=mng_info->image_box.left+mng_info->x_off[object_id];\n crop_box.right=mng_info->image_box.right+mng_info->x_off[object_id];\n crop_box.top=mng_info->image_box.top+mng_info->y_off[object_id];\n crop_box.bottom=mng_info->image_box.bottom+mng_info->y_off[object_id];\n crop_box=mng_minimum_box(crop_box,mng_info->clip);\n crop_box=mng_minimum_box(crop_box,mng_info->frame);\n crop_box=mng_minimum_box(crop_box,mng_info->object_clip[object_id]);\n if ((crop_box.left != (mng_info->image_box.left\n +mng_info->x_off[object_id])) ||\n (crop_box.right != (mng_info->image_box.right\n +mng_info->x_off[object_id])) ||\n (crop_box.top != (mng_info->image_box.top\n +mng_info->y_off[object_id])) ||\n (crop_box.bottom != (mng_info->image_box.bottom\n +mng_info->y_off[object_id])))\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Crop the PNG image\");", " if ((crop_box.left < crop_box.right) &&\n (crop_box.top < crop_box.bottom))\n {\n Image\n *im;", " RectangleInfo\n crop_info;", " /*\n Crop_info is with respect to the upper left corner of\n the image.\n */\n crop_info.x=(crop_box.left-mng_info->x_off[object_id]);\n crop_info.y=(crop_box.top-mng_info->y_off[object_id]);\n crop_info.width=(size_t) (crop_box.right-crop_box.left);\n crop_info.height=(size_t) (crop_box.bottom-crop_box.top);\n image->page.width=image->columns;\n image->page.height=image->rows;\n image->page.x=0;\n image->page.y=0;\n im=CropImage(image,&crop_info,exception);", " if (im != (Image *) NULL)\n {\n image->columns=im->columns;\n image->rows=im->rows;\n im=DestroyImage(im);\n image->page.width=image->columns;\n image->page.height=image->rows;\n image->page.x=crop_box.left;\n image->page.y=crop_box.top;\n }\n }", " else\n {\n /*\n No pixels in crop area. The MNG spec still requires\n a layer, though, so make a single transparent pixel in\n the top left corner.\n */\n image->columns=1;\n image->rows=1;\n image->colors=2;\n (void) SetImageBackgroundColor(image);\n image->page.width=1;\n image->page.height=1;\n image->page.x=0;\n image->page.y=0;\n }\n }\n#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED\n image=mng_info->image;\n#endif\n }", "#if (MAGICKCORE_QUANTUM_DEPTH > 16)\n /* PNG does not handle depths greater than 16 so reduce it even\n * if lossy, and promote any depths > 8 to 16.\n */\n if (image->depth > 16)\n image->depth=16;\n#endif", "#if (MAGICKCORE_QUANTUM_DEPTH > 8)\n if (image->depth > 8)\n {\n /* To do: fill low byte properly */\n image->depth=16;\n }", " if (LosslessReduceDepthOK(image) != MagickFalse)\n image->depth = 8;\n#endif", " GetImageException(image,exception);", " if (image_info->number_scenes != 0)\n {\n if (mng_info->scenes_found >\n (ssize_t) (image_info->first_scene+image_info->number_scenes))\n break;\n }", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Finished reading image datastream.\");", " } while (LocaleCompare(image_info->magick,\"MNG\") == 0);", " (void) CloseBlob(image);", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Finished reading all image datastreams.\");", "#if defined(MNG_INSERT_LAYERS)\n if (insert_layers && !mng_info->image_found && (mng_info->mng_width) &&\n (mng_info->mng_height))\n {\n /*\n Insert a background layer if nothing else was found.\n */\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" No images found. Inserting a background layer.\");", " if (GetAuthenticPixelQueue(image) != (PixelPacket *) NULL)\n {\n /*\n Allocate next image structure.\n */\n AcquireNextImage(image_info,image);\n if (GetNextImageInList(image) == (Image *) NULL)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Allocation failed, returning NULL.\");", " return(DestroyImageList(image));\n }\n image=SyncNextImageInList(image);\n }\n image->columns=mng_info->mng_width;\n image->rows=mng_info->mng_height;\n image->page.width=mng_info->mng_width;\n image->page.height=mng_info->mng_height;\n image->page.x=0;\n image->page.y=0;\n image->background_color=mng_background_color;\n image->matte=MagickFalse;", " if (image_info->ping == MagickFalse)\n (void) SetImageBackgroundColor(image);", " mng_info->image_found++;\n }\n#endif\n image->iterations=mng_iterations;", " if (mng_iterations == 1)\n image->start_loop=MagickTrue;", " while (GetPreviousImageInList(image) != (Image *) NULL)\n {\n image_count++;\n if (image_count > 10*mng_info->image_found)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" No beginning\");", " (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"Linked list is corrupted, beginning of list not found\",\n \"`%s'\",image_info->filename);", " return(DestroyImageList(image));\n }", " image=GetPreviousImageInList(image);", " if (GetNextImageInList(image) == (Image *) NULL)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" Corrupt list\");", " (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"Linked list is corrupted; next_image is NULL\",\"`%s'\",\n image_info->filename);\n }\n }", " if (mng_info->ticks_per_second && mng_info->image_found > 1 &&\n GetNextImageInList(image) ==\n (Image *) NULL)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" First image null\");", " (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"image->next for first image is NULL but shouldn't be.\",\n \"`%s'\",image_info->filename);\n }", " if (mng_info->image_found == 0)\n {\n if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" No visible images found.\");", " (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"No visible images in file\",\"`%s'\",image_info->filename);", " return(DestroyImageList(image));\n }", " if (mng_info->ticks_per_second)\n final_delay=1UL*MagickMax(image->ticks_per_second,1L)*\n final_delay/mng_info->ticks_per_second;", " else\n image->start_loop=MagickTrue;", " /* Find final nonzero image delay */\n final_image_delay=0;", " while (GetNextImageInList(image) != (Image *) NULL)\n {\n if (image->delay)\n final_image_delay=image->delay;", " image=GetNextImageInList(image);\n }", " if (final_delay < final_image_delay)\n final_delay=final_image_delay;", " image->delay=final_delay;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" image->delay=%.20g, final_delay=%.20g\",(double) image->delay,\n (double) final_delay);", " if (logging != MagickFalse)\n {\n int\n scene;", " scene=0;\n image=GetFirstImageInList(image);", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Before coalesce:\");", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" scene 0 delay=%.20g\",(double) image->delay);", " while (GetNextImageInList(image) != (Image *) NULL)\n {\n image=GetNextImageInList(image);\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" scene %.20g delay=%.20g\",(double) scene++,(double) image->delay);\n }\n }", " image=GetFirstImageInList(image);\n#ifdef MNG_COALESCE_LAYERS\n if (insert_layers)\n {\n Image\n *next_image,\n *next;", " size_t\n scene;", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\" Coalesce Images\");", " scene=image->scene;\n next_image=CoalesceImages(image,&image->exception);", " if (next_image == (Image *) NULL)\n ThrowReaderException(ResourceLimitError,\"MemoryAllocationFailed\");", " image=DestroyImageList(image);\n image=next_image;", " for (next=image; next != (Image *) NULL; next=next_image)\n {\n next->page.width=mng_info->mng_width;\n next->page.height=mng_info->mng_height;\n next->page.x=0;\n next->page.y=0;\n next->scene=scene++;\n next_image=GetNextImageInList(next);", " if (next_image == (Image *) NULL)\n break;", " if (next->delay == 0)\n {\n scene--;\n next_image->previous=GetPreviousImageInList(next);\n if (GetPreviousImageInList(next) == (Image *) NULL)\n image=next_image;\n else\n next->previous->next=next_image;\n next=DestroyImage(next);\n }\n }\n }\n#endif", " while (GetNextImageInList(image) != (Image *) NULL)\n image=GetNextImageInList(image);", " image->dispose=BackgroundDispose;", " if (logging != MagickFalse)\n {\n int\n scene;", " scene=0;\n image=GetFirstImageInList(image);", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" After coalesce:\");", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" scene 0 delay=%.20g dispose=%.20g\",(double) image->delay,\n (double) image->dispose);", " while (GetNextImageInList(image) != (Image *) NULL)\n {\n image=GetNextImageInList(image);", " (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" scene %.20g delay=%.20g dispose=%.20g\",(double) scene++,\n (double) image->delay,(double) image->dispose);\n }\n }", " if (logging != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" exit ReadOneJNGImage();\");", " return(image);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 27456, "char_start": 27373, "chars": "(i < 0) || (i >= MNG_MAX_OBJECTS))\n continue;\n if (" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/78d4c5db50fbab0b4beb69c46c6167f2c6513dec", "file_name": "coders/png.c", "func_name": "ReadOneMNGImage", "line_changes": { "added": [ { "char_end": 27408, "char_start": 27353, "line": " if ((i < 0) || (i >= MNG_MAX_OBJECTS))\n", "line_no": 885 }, { "char_end": 27436, "char_start": 27408, "line": " continue;\n", "line_no": 886 } ], "deleted": [] }, "vul_type": "cwe-125" }
471
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,\n Image *image)\n{\n const char\n *mode,\n *option;", " CompressionType\n compression;", " EndianType\n endian_type;", " MagickBooleanType\n debug,\n status;", " MagickOffsetType\n scene;", " QuantumInfo\n *quantum_info;", " QuantumType\n quantum_type;", " register ssize_t\n i;", " size_t\n imageListLength;", " ssize_t\n y;", " TIFF\n *tiff;", " TIFFInfo\n tiff_info;", " uint16\n bits_per_sample,\n compress_tag,\n endian,\n photometric,\n predictor;", " unsigned char\n *pixels;", " /*\n Open TIFF file.\n */\n assert(image_info != (const ImageInfo *) NULL);\n assert(image_info->signature == MagickCoreSignature);\n assert(image != (Image *) NULL);\n assert(image->signature == MagickCoreSignature);\n if (image->debug != MagickFalse)\n (void) LogMagickEvent(TraceEvent,GetMagickModule(),\"%s\",image->filename);\n status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);\n if (status == MagickFalse)\n return(status);\n (void) SetMagickThreadValue(tiff_exception,&image->exception);\n endian_type=UndefinedEndian;\n option=GetImageOption(image_info,\"tiff:endian\");\n if (option != (const char *) NULL)\n {\n if (LocaleNCompare(option,\"msb\",3) == 0)\n endian_type=MSBEndian;\n if (LocaleNCompare(option,\"lsb\",3) == 0)\n endian_type=LSBEndian;;\n }\n switch (endian_type)\n {\n case LSBEndian: mode=\"wl\"; break;\n case MSBEndian: mode=\"wb\"; break;\n default: mode=\"w\"; break;\n }\n#if defined(TIFF_VERSION_BIG)\n if (LocaleCompare(image_info->magick,\"TIFF64\") == 0)\n switch (endian_type)\n {\n case LSBEndian: mode=\"wl8\"; break;\n case MSBEndian: mode=\"wb8\"; break;\n default: mode=\"w8\"; break;\n }\n#endif\n tiff=TIFFClientOpen(image->filename,mode,(thandle_t) image,TIFFReadBlob,\n TIFFWriteBlob,TIFFSeekBlob,TIFFCloseBlob,TIFFGetBlobSize,TIFFMapBlob,\n TIFFUnmapBlob);\n if (tiff == (TIFF *) NULL)\n return(MagickFalse);\n if (image->exception.severity > ErrorException)\n {\n TIFFClose(tiff);\n return(MagickFalse);\n }\n (void) DeleteImageProfile(image,\"tiff:37724\");\n scene=0;\n debug=IsEventLogging();\n (void) debug;\n imageListLength=GetImageListLength(image);\n do\n {\n /*\n Initialize TIFF fields.\n */\n if ((image_info->type != UndefinedType) &&\n (image_info->type != OptimizeType))\n (void) SetImageType(image,image_info->type);\n compression=UndefinedCompression;\n if (image->compression != JPEGCompression)\n compression=image->compression;\n if (image_info->compression != UndefinedCompression)\n compression=image_info->compression;\n switch (compression)\n {\n case FaxCompression:\n case Group4Compression:\n {\n (void) SetImageType(image,BilevelType);\n (void) SetImageDepth(image,1);\n break;\n }\n case JPEGCompression:\n {\n (void) SetImageStorageClass(image,DirectClass);\n (void) SetImageDepth(image,8);\n break;\n }\n default:\n break;\n }\n quantum_info=AcquireQuantumInfo(image_info,image);\n if (quantum_info == (QuantumInfo *) NULL)\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n if ((image->storage_class != PseudoClass) && (image->depth >= 32) &&\n (quantum_info->format == UndefinedQuantumFormat) &&\n (IsHighDynamicRangeImage(image,&image->exception) != MagickFalse))\n {\n status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);\n if (status == MagickFalse)\n {\n quantum_info=DestroyQuantumInfo(quantum_info);\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n }\n }\n if ((LocaleCompare(image_info->magick,\"PTIF\") == 0) &&\n (GetPreviousImageInList(image) != (Image *) NULL))\n (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_REDUCEDIMAGE);\n if ((image->columns != (uint32) image->columns) ||\n (image->rows != (uint32) image->rows))\n ThrowWriterException(ImageError,\"WidthOrHeightExceedsLimit\");\n (void) TIFFSetField(tiff,TIFFTAG_IMAGELENGTH,(uint32) image->rows);\n (void) TIFFSetField(tiff,TIFFTAG_IMAGEWIDTH,(uint32) image->columns);\n switch (compression)\n {\n case FaxCompression:\n {\n compress_tag=COMPRESSION_CCITTFAX3;\n option=GetImageOption(image_info,\"quantum:polarity\");\n if (option == (const char *) NULL)\n SetQuantumMinIsWhite(quantum_info,MagickTrue);\n break;\n }\n case Group4Compression:\n {\n compress_tag=COMPRESSION_CCITTFAX4;\n option=GetImageOption(image_info,\"quantum:polarity\");\n if (option == (const char *) NULL)\n SetQuantumMinIsWhite(quantum_info,MagickTrue);\n break;\n }\n#if defined(COMPRESSION_JBIG)\n case JBIG1Compression:\n {\n compress_tag=COMPRESSION_JBIG;\n break;\n }\n#endif\n case JPEGCompression:\n {\n compress_tag=COMPRESSION_JPEG;\n break;\n }\n#if defined(COMPRESSION_LZMA)\n case LZMACompression:\n {\n compress_tag=COMPRESSION_LZMA;\n break;\n }\n#endif\n case LZWCompression:\n {\n compress_tag=COMPRESSION_LZW;\n break;\n }\n case RLECompression:\n {\n compress_tag=COMPRESSION_PACKBITS;\n break;\n }\n#if defined(COMPRESSION_WEBP)\n case WebPCompression:\n {\n compress_tag=COMPRESSION_WEBP;\n break;\n }\n#endif\n case ZipCompression:\n {\n compress_tag=COMPRESSION_ADOBE_DEFLATE;\n break;\n }\n#if defined(COMPRESSION_ZSTD)\n case ZstdCompression:\n {\n compress_tag=COMPRESSION_ZSTD;\n break;\n }\n#endif\n case NoCompression:\n default:\n {\n compress_tag=COMPRESSION_NONE;\n break;\n }\n }\n#if defined(MAGICKCORE_HAVE_TIFFISCODECCONFIGURED) || (TIFFLIB_VERSION > 20040919)\n if ((compress_tag != COMPRESSION_NONE) &&\n (TIFFIsCODECConfigured(compress_tag) == 0))\n {\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"CompressionNotSupported\",\"`%s'\",CommandOptionToMnemonic(\n MagickCompressOptions,(ssize_t) compression));\n compress_tag=COMPRESSION_NONE;\n }\n#else\n switch (compress_tag)\n {\n#if defined(CCITT_SUPPORT)\n case COMPRESSION_CCITTFAX3:\n case COMPRESSION_CCITTFAX4:\n#endif\n#if defined(YCBCR_SUPPORT) && defined(JPEG_SUPPORT)\n case COMPRESSION_JPEG:\n#endif\n#if defined(LZMA_SUPPORT) && defined(COMPRESSION_LZMA)\n case COMPRESSION_LZMA:\n#endif\n#if defined(LZW_SUPPORT)\n case COMPRESSION_LZW:\n#endif\n#if defined(PACKBITS_SUPPORT)\n case COMPRESSION_PACKBITS:\n#endif\n#if defined(ZIP_SUPPORT)\n case COMPRESSION_ADOBE_DEFLATE:\n#endif\n case COMPRESSION_NONE:\n break;\n default:\n {\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"CompressionNotSupported\",\"`%s'\",CommandOptionToMnemonic(\n MagickCompressOptions,(ssize_t) compression));\n compress_tag=COMPRESSION_NONE;\n break;\n }\n }\n#endif\n if (image->colorspace == CMYKColorspace)\n {\n photometric=PHOTOMETRIC_SEPARATED;\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,4);\n (void) TIFFSetField(tiff,TIFFTAG_INKSET,INKSET_CMYK);\n }\n else\n {\n /*\n Full color TIFF raster.\n */\n if (image->colorspace == LabColorspace)\n {\n photometric=PHOTOMETRIC_CIELAB;\n EncodeLabImage(image,&image->exception);\n }\n else\n if (image->colorspace == YCbCrColorspace)\n {\n photometric=PHOTOMETRIC_YCBCR;\n (void) TIFFSetField(tiff,TIFFTAG_YCBCRSUBSAMPLING,1,1);\n (void) SetImageStorageClass(image,DirectClass);\n (void) SetImageDepth(image,8);\n }\n else\n photometric=PHOTOMETRIC_RGB;\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,3);\n if ((image_info->type != TrueColorType) &&\n (image_info->type != TrueColorMatteType))\n {\n if ((image_info->type != PaletteType) &&\n (SetImageGray(image,&image->exception) != MagickFalse))\n {\n photometric=(uint16) (quantum_info->min_is_white !=\n MagickFalse ? PHOTOMETRIC_MINISWHITE :\n PHOTOMETRIC_MINISBLACK);\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,1);\n if ((image->depth == 1) && (image->matte == MagickFalse))\n SetImageMonochrome(image,&image->exception);\n }\n else\n if (image->storage_class == PseudoClass)\n {\n size_t\n depth;", " /*\n Colormapped TIFF raster.\n */\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,1);\n photometric=PHOTOMETRIC_PALETTE;\n depth=1;\n while ((GetQuantumRange(depth)+1) < image->colors)\n depth<<=1;\n status=SetQuantumDepth(image,quantum_info,depth);\n if (status == MagickFalse)\n ThrowWriterException(ResourceLimitError,\n \"MemoryAllocationFailed\");\n }\n }\n }\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_FILLORDER,&endian);\n if ((compress_tag == COMPRESSION_CCITTFAX3) ||\n (compress_tag == COMPRESSION_CCITTFAX4))\n {\n if ((photometric != PHOTOMETRIC_MINISWHITE) &&\n (photometric != PHOTOMETRIC_MINISBLACK))\n {\n compress_tag=COMPRESSION_NONE;\n endian=FILLORDER_MSB2LSB;\n }\n }\n option=GetImageOption(image_info,\"tiff:fill-order\");\n if (option != (const char *) NULL)\n {\n if (LocaleNCompare(option,\"msb\",3) == 0)\n endian=FILLORDER_MSB2LSB;\n if (LocaleNCompare(option,\"lsb\",3) == 0)\n endian=FILLORDER_LSB2MSB;\n }\n (void) TIFFSetField(tiff,TIFFTAG_COMPRESSION,compress_tag);\n (void) TIFFSetField(tiff,TIFFTAG_FILLORDER,endian);\n (void) TIFFSetField(tiff,TIFFTAG_BITSPERSAMPLE,quantum_info->depth);\n if (image->matte != MagickFalse)\n {\n uint16\n extra_samples,\n sample_info[1],\n samples_per_pixel;", " /*\n TIFF has a matte channel.\n */\n extra_samples=1;\n sample_info[0]=EXTRASAMPLE_UNASSALPHA;\n option=GetImageOption(image_info,\"tiff:alpha\");\n if (option != (const char *) NULL)\n {\n if (LocaleCompare(option,\"associated\") == 0)\n sample_info[0]=EXTRASAMPLE_ASSOCALPHA;\n else\n if (LocaleCompare(option,\"unspecified\") == 0)\n sample_info[0]=EXTRASAMPLE_UNSPECIFIED;\n }\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLESPERPIXEL,\n &samples_per_pixel);\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,samples_per_pixel+1);\n (void) TIFFSetField(tiff,TIFFTAG_EXTRASAMPLES,extra_samples,\n &sample_info);\n if (sample_info[0] == EXTRASAMPLE_ASSOCALPHA)\n SetQuantumAlphaType(quantum_info,AssociatedQuantumAlpha);\n }\n (void) TIFFSetField(tiff,TIFFTAG_PHOTOMETRIC,photometric);\n switch (quantum_info->format)\n {\n case FloatingPointQuantumFormat:\n {\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLEFORMAT,SAMPLEFORMAT_IEEEFP);\n (void) TIFFSetField(tiff,TIFFTAG_SMINSAMPLEVALUE,quantum_info->minimum);\n (void) TIFFSetField(tiff,TIFFTAG_SMAXSAMPLEVALUE,quantum_info->maximum);\n break;\n }\n case SignedQuantumFormat:\n {\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLEFORMAT,SAMPLEFORMAT_INT);\n break;\n }\n case UnsignedQuantumFormat:\n {\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLEFORMAT,SAMPLEFORMAT_UINT);\n break;\n }\n default:\n break;\n }\n (void) TIFFSetField(tiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);\n if (photometric == PHOTOMETRIC_RGB)\n if ((image_info->interlace == PlaneInterlace) ||\n (image_info->interlace == PartitionInterlace))\n (void) TIFFSetField(tiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_SEPARATE);\n predictor=0;\n switch (compress_tag)\n {\n case COMPRESSION_JPEG:\n {\n#if defined(JPEG_SUPPORT)\n if (image_info->quality != UndefinedCompressionQuality)\n (void) TIFFSetField(tiff,TIFFTAG_JPEGQUALITY,image_info->quality);\n (void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RAW);\n if (IssRGBCompatibleColorspace(image->colorspace) != MagickFalse)\n {\n const char\n *value;", " (void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RGB);\n if (image->colorspace == YCbCrColorspace)\n {\n const char\n *sampling_factor;", " GeometryInfo\n geometry_info;", " MagickStatusType\n flags;", " sampling_factor=(const char *) NULL;\n value=GetImageProperty(image,\"jpeg:sampling-factor\");\n if (value != (char *) NULL)\n {\n sampling_factor=value;\n if (image->debug != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Input sampling-factors=%s\",sampling_factor);\n }\n if (image_info->sampling_factor != (char *) NULL)\n sampling_factor=image_info->sampling_factor;\n if (sampling_factor != (const char *) NULL)\n {\n flags=ParseGeometry(sampling_factor,&geometry_info);\n if ((flags & SigmaValue) == 0)\n geometry_info.sigma=geometry_info.rho;\n (void) TIFFSetField(tiff,TIFFTAG_YCBCRSUBSAMPLING,(uint16)\n geometry_info.rho,(uint16) geometry_info.sigma);\n }\n }\n }\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (bits_per_sample == 12)\n (void) TIFFSetField(tiff,TIFFTAG_JPEGTABLESMODE,JPEGTABLESMODE_QUANT);\n#endif\n break;\n }\n case COMPRESSION_ADOBE_DEFLATE:\n {\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n (void) TIFFSetField(tiff,TIFFTAG_ZIPQUALITY,(long) (\n image_info->quality == UndefinedCompressionQuality ? 7 :\n MagickMin((ssize_t) image_info->quality/10,9)));\n break;\n }\n case COMPRESSION_CCITTFAX3:\n {\n /*\n Byte-aligned EOL.\n */\n (void) TIFFSetField(tiff,TIFFTAG_GROUP3OPTIONS,4);\n break;\n }\n case COMPRESSION_CCITTFAX4:\n break;\n#if defined(LZMA_SUPPORT) && defined(COMPRESSION_LZMA)\n case COMPRESSION_LZMA:\n {\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n (void) TIFFSetField(tiff,TIFFTAG_LZMAPRESET,(long) (\n image_info->quality == UndefinedCompressionQuality ? 7 :\n MagickMin((ssize_t) image_info->quality/10,9)));\n break;\n }\n#endif\n case COMPRESSION_LZW:\n {\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n break;\n }\n#if defined(WEBP_SUPPORT) && defined(COMPRESSION_WEBP)\n case COMPRESSION_WEBP:\n {\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n (void) TIFFSetField(tiff,TIFFTAG_WEBP_LEVEL,mage_info->quality);\n if (image_info->quality >= 100)\n (void) TIFFSetField(tiff,TIFFTAG_WEBP_LOSSLESS,1);\n break;\n }\n#endif\n#if defined(ZSTD_SUPPORT) && defined(COMPRESSION_ZSTD)\n case COMPRESSION_ZSTD:\n {\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n (void) TIFFSetField(tiff,TIFFTAG_ZSTD_LEVEL,22*image_info->quality/\n 100.0);\n break;\n }\n#endif\n default:\n break;\n }\n option=GetImageOption(image_info,\"tiff:predictor\");\n if (option != (const char * ) NULL)\n predictor=(size_t) strtol(option,(char **) NULL,10);\n if (predictor != 0)\n (void) TIFFSetField(tiff,TIFFTAG_PREDICTOR,predictor);\n if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))\n {\n unsigned short\n units;", " /*\n Set image resolution.\n */\n units=RESUNIT_NONE;\n if (image->units == PixelsPerInchResolution)\n units=RESUNIT_INCH;\n if (image->units == PixelsPerCentimeterResolution)\n units=RESUNIT_CENTIMETER;\n (void) TIFFSetField(tiff,TIFFTAG_RESOLUTIONUNIT,(uint16) units);\n (void) TIFFSetField(tiff,TIFFTAG_XRESOLUTION,image->x_resolution);\n (void) TIFFSetField(tiff,TIFFTAG_YRESOLUTION,image->y_resolution);\n if ((image->page.x < 0) || (image->page.y < 0))\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"TIFF: negative image positions unsupported\",\"%s\",\n image->filename);\n if ((image->page.x > 0) && (image->x_resolution > 0.0))\n {\n /*\n Set horizontal image position.\n */\n (void) TIFFSetField(tiff,TIFFTAG_XPOSITION,(float) image->page.x/\n image->x_resolution);\n }\n if ((image->page.y > 0) && (image->y_resolution > 0.0))\n {\n /*\n Set vertical image position.\n */\n (void) TIFFSetField(tiff,TIFFTAG_YPOSITION,(float) image->page.y/\n image->y_resolution);\n }\n }\n if (image->chromaticity.white_point.x != 0.0)\n {\n float\n chromaticity[6];", " /*\n Set image chromaticity.\n */\n chromaticity[0]=(float) image->chromaticity.red_primary.x;\n chromaticity[1]=(float) image->chromaticity.red_primary.y;\n chromaticity[2]=(float) image->chromaticity.green_primary.x;\n chromaticity[3]=(float) image->chromaticity.green_primary.y;\n chromaticity[4]=(float) image->chromaticity.blue_primary.x;\n chromaticity[5]=(float) image->chromaticity.blue_primary.y;\n (void) TIFFSetField(tiff,TIFFTAG_PRIMARYCHROMATICITIES,chromaticity);\n chromaticity[0]=(float) image->chromaticity.white_point.x;\n chromaticity[1]=(float) image->chromaticity.white_point.y;\n (void) TIFFSetField(tiff,TIFFTAG_WHITEPOINT,chromaticity);\n }\n if ((LocaleCompare(image_info->magick,\"PTIF\") != 0) &&\n (image_info->adjoin != MagickFalse) && (imageListLength > 1))\n {\n (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE);\n if (image->scene != 0)\n (void) TIFFSetField(tiff,TIFFTAG_PAGENUMBER,(uint16) image->scene,\n imageListLength);\n }\n if (image->orientation != UndefinedOrientation)\n (void) TIFFSetField(tiff,TIFFTAG_ORIENTATION,(uint16) image->orientation);\n else\n (void) TIFFSetField(tiff,TIFFTAG_ORIENTATION,ORIENTATION_TOPLEFT);\n (void) TIFFSetProfiles(tiff,image);\n {\n uint16\n page,\n pages;", " page=(uint16) scene;\n pages=(uint16) imageListLength;\n if ((LocaleCompare(image_info->magick,\"PTIF\") != 0) &&\n (image_info->adjoin != MagickFalse) && (pages > 1))\n (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE);\n (void) TIFFSetField(tiff,TIFFTAG_PAGENUMBER,page,pages);\n }\n (void) TIFFSetProperties(tiff,image_info,image);\nDisableMSCWarning(4127)\n if (0)\nRestoreMSCWarning\n (void) TIFFSetEXIFProperties(tiff,image);\n /*\n Write image scanlines.\n */\n if (GetTIFFInfo(image_info,tiff,&tiff_info) == MagickFalse)\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n quantum_info->endian=LSBEndian;\n pixels=GetQuantumPixels(quantum_info);\n tiff_info.scanline=GetQuantumPixels(quantum_info);\n switch (photometric)\n {\n case PHOTOMETRIC_CIELAB:\n case PHOTOMETRIC_YCBCR:\n case PHOTOMETRIC_RGB:\n {\n /*\n RGB TIFF image.\n */\n switch (image_info->interlace)\n {\n case NoInterlace:\n default:\n {\n quantum_type=RGBQuantum;\n if (image->matte != MagickFalse)\n quantum_type=RGBAQuantum;\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,quantum_type,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)\n y,image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n break;\n }\n case PlaneInterlace:\n case PartitionInterlace:\n {\n /*\n Plane interlacing: RRRRRR...GGGGGG...BBBBBB...\n */\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,RedQuantum,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)\n break;\n }\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,100,400);\n if (status == MagickFalse)\n break;\n }\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,GreenQuantum,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,1,image) == -1)\n break;\n }\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,200,400);\n if (status == MagickFalse)\n break;\n }\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,BlueQuantum,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,2,image) == -1)\n break;\n }\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,300,400);\n if (status == MagickFalse)\n break;\n }\n if (image->matte != MagickFalse)\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,\n &image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,AlphaQuantum,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,3,image) == -1)\n break;\n }\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,400,400);\n if (status == MagickFalse)\n break;\n }\n break;\n }\n }\n break;\n }\n case PHOTOMETRIC_SEPARATED:\n {\n /*\n CMYK TIFF image.\n */\n quantum_type=CMYKQuantum;\n if (image->matte != MagickFalse)\n quantum_type=CMYKAQuantum;\n if (image->colorspace != CMYKColorspace)\n (void) TransformImageColorspace(image,CMYKColorspace);\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,quantum_type,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n break;\n }\n case PHOTOMETRIC_PALETTE:\n {\n uint16\n *blue,\n *green,\n *red;", " /*\n Colormapped TIFF image.\n */\n red=(uint16 *) AcquireQuantumMemory(65536,sizeof(*red));\n green=(uint16 *) AcquireQuantumMemory(65536,sizeof(*green));\n blue=(uint16 *) AcquireQuantumMemory(65536,sizeof(*blue));\n if ((red == (uint16 *) NULL) || (green == (uint16 *) NULL) ||\n (blue == (uint16 *) NULL))\n {\n if (red != (uint16 *) NULL)\n red=(uint16 *) RelinquishMagickMemory(red);\n if (green != (uint16 *) NULL)\n green=(uint16 *) RelinquishMagickMemory(green);\n if (blue != (uint16 *) NULL)\n blue=(uint16 *) RelinquishMagickMemory(blue);\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n }\n /*\n Initialize TIFF colormap.\n */\n (void) memset(red,0,65536*sizeof(*red));\n (void) memset(green,0,65536*sizeof(*green));\n (void) memset(blue,0,65536*sizeof(*blue));\n for (i=0; i < (ssize_t) image->colors; i++)\n {\n red[i]=ScaleQuantumToShort(image->colormap[i].red);\n green[i]=ScaleQuantumToShort(image->colormap[i].green);\n blue[i]=ScaleQuantumToShort(image->colormap[i].blue);\n }\n (void) TIFFSetField(tiff,TIFFTAG_COLORMAP,red,green,blue);\n red=(uint16 *) RelinquishMagickMemory(red);\n green=(uint16 *) RelinquishMagickMemory(green);\n blue=(uint16 *) RelinquishMagickMemory(blue);\n }\n default:\n {\n /*\n Convert PseudoClass packets to contiguous grayscale scanlines.\n */\n quantum_type=IndexQuantum;\n if (image->matte != MagickFalse)\n {\n if (photometric != PHOTOMETRIC_PALETTE)\n quantum_type=GrayAlphaQuantum;\n else\n quantum_type=IndexAlphaQuantum;\n }\n else\n if (photometric != PHOTOMETRIC_PALETTE)\n quantum_type=GrayQuantum;\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,quantum_type,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n break;\n }\n }\n quantum_info=DestroyQuantumInfo(quantum_info);\n if (image->colorspace == LabColorspace)\n DecodeLabImage(image,&image->exception);\n DestroyTIFFInfo(&tiff_info);", " if (image->exception.severity > ErrorException)\n break;", "DisableMSCWarning(4127)\n if (0 && (image_info->verbose != MagickFalse))\nRestoreMSCWarning\n TIFFPrintDirectory(tiff,stdout,MagickFalse);", " (void) TIFFWriteDirectory(tiff);", " image=SyncNextImageInList(image);\n if (image == (Image *) NULL)\n break;\n status=SetImageProgress(image,SaveImagesTag,scene++,imageListLength);\n if (status == MagickFalse)\n break;\n } while (image_info->adjoin != MagickFalse);\n TIFFClose(tiff);", " return(image->exception.severity > ErrorException ? MagickFalse : MagickTrue);", "}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 30490, "char_start": 30489, "chars": "f" }, { "char_end": 30492, "char_start": 30491, "chars": "(" }, { "char_end": 30557, "char_start": 30516, "chars": " == 0)\n {\n status=MagickFalse" }, { "char_end": 30582, "char_start": 30559, "chars": " break;\n }\n" }, { "char_end": 30864, "char_start": 30862, "chars": "tu" } ], "deleted": [ { "char_end": 30405, "char_start": 30340, "chars": " if (image->exception.severity > ErrorException)\n break;\n" }, { "char_end": 30556, "char_start": 30553, "chars": "(vo" }, { "char_end": 30559, "char_start": 30557, "chars": "d)" }, { "char_end": 30880, "char_start": 30863, "chars": "image->exception." }, { "char_end": 30886, "char_start": 30881, "chars": "everi" }, { "char_end": 30901, "char_start": 30887, "chars": "y > ErrorExcep" }, { "char_end": 30917, "char_start": 30902, "chars": "ion ? MagickFal" }, { "char_end": 30932, "char_start": 30918, "chars": "e : MagickTrue" } ] }, "commit_link": "github.com/ImageMagick/ImageMagick6/commit/3c53413eb544cc567309b4c86485eae43e956112", "file_name": "coders/tiff.c", "func_name": "WriteTIFFImage", "line_changes": { "added": [ { "char_end": 30523, "char_start": 30484, "line": " if (TIFFWriteDirectory(tiff) == 0)\n", "line_no": 897 }, { "char_end": 30531, "char_start": 30523, "line": " {\n", "line_no": 898 }, { "char_end": 30559, "char_start": 30531, "line": " status=MagickFalse;\n", "line_no": 899 }, { "char_end": 30574, "char_start": 30559, "line": " break;\n", "line_no": 900 }, { "char_end": 30582, "char_start": 30574, "line": " }\n", "line_no": 901 }, { "char_end": 30868, "char_start": 30850, "line": " return(status);\n", "line_no": 910 } ], "deleted": [ { "char_end": 30392, "char_start": 30340, "line": " if (image->exception.severity > ErrorException)\n", "line_no": 893 }, { "char_end": 30405, "char_start": 30392, "line": " break;\n", "line_no": 894 }, { "char_end": 30586, "char_start": 30549, "line": " (void) TIFFWriteDirectory(tiff);\n", "line_no": 899 }, { "char_end": 30935, "char_start": 30854, "line": " return(image->exception.severity > ErrorException ? MagickFalse : MagickTrue);\n", "line_no": 908 } ] }, "vul_type": "cwe-125" }
472
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,\n Image *image)\n{\n const char\n *mode,\n *option;", " CompressionType\n compression;", " EndianType\n endian_type;", " MagickBooleanType\n debug,\n status;", " MagickOffsetType\n scene;", " QuantumInfo\n *quantum_info;", " QuantumType\n quantum_type;", " register ssize_t\n i;", " size_t\n imageListLength;", " ssize_t\n y;", " TIFF\n *tiff;", " TIFFInfo\n tiff_info;", " uint16\n bits_per_sample,\n compress_tag,\n endian,\n photometric,\n predictor;", " unsigned char\n *pixels;", " /*\n Open TIFF file.\n */\n assert(image_info != (const ImageInfo *) NULL);\n assert(image_info->signature == MagickCoreSignature);\n assert(image != (Image *) NULL);\n assert(image->signature == MagickCoreSignature);\n if (image->debug != MagickFalse)\n (void) LogMagickEvent(TraceEvent,GetMagickModule(),\"%s\",image->filename);\n status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);\n if (status == MagickFalse)\n return(status);\n (void) SetMagickThreadValue(tiff_exception,&image->exception);\n endian_type=UndefinedEndian;\n option=GetImageOption(image_info,\"tiff:endian\");\n if (option != (const char *) NULL)\n {\n if (LocaleNCompare(option,\"msb\",3) == 0)\n endian_type=MSBEndian;\n if (LocaleNCompare(option,\"lsb\",3) == 0)\n endian_type=LSBEndian;;\n }\n switch (endian_type)\n {\n case LSBEndian: mode=\"wl\"; break;\n case MSBEndian: mode=\"wb\"; break;\n default: mode=\"w\"; break;\n }\n#if defined(TIFF_VERSION_BIG)\n if (LocaleCompare(image_info->magick,\"TIFF64\") == 0)\n switch (endian_type)\n {\n case LSBEndian: mode=\"wl8\"; break;\n case MSBEndian: mode=\"wb8\"; break;\n default: mode=\"w8\"; break;\n }\n#endif\n tiff=TIFFClientOpen(image->filename,mode,(thandle_t) image,TIFFReadBlob,\n TIFFWriteBlob,TIFFSeekBlob,TIFFCloseBlob,TIFFGetBlobSize,TIFFMapBlob,\n TIFFUnmapBlob);\n if (tiff == (TIFF *) NULL)\n return(MagickFalse);\n if (image->exception.severity > ErrorException)\n {\n TIFFClose(tiff);\n return(MagickFalse);\n }\n (void) DeleteImageProfile(image,\"tiff:37724\");\n scene=0;\n debug=IsEventLogging();\n (void) debug;\n imageListLength=GetImageListLength(image);\n do\n {\n /*\n Initialize TIFF fields.\n */\n if ((image_info->type != UndefinedType) &&\n (image_info->type != OptimizeType))\n (void) SetImageType(image,image_info->type);\n compression=UndefinedCompression;\n if (image->compression != JPEGCompression)\n compression=image->compression;\n if (image_info->compression != UndefinedCompression)\n compression=image_info->compression;\n switch (compression)\n {\n case FaxCompression:\n case Group4Compression:\n {\n (void) SetImageType(image,BilevelType);\n (void) SetImageDepth(image,1);\n break;\n }\n case JPEGCompression:\n {\n (void) SetImageStorageClass(image,DirectClass);\n (void) SetImageDepth(image,8);\n break;\n }\n default:\n break;\n }\n quantum_info=AcquireQuantumInfo(image_info,image);\n if (quantum_info == (QuantumInfo *) NULL)\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n if ((image->storage_class != PseudoClass) && (image->depth >= 32) &&\n (quantum_info->format == UndefinedQuantumFormat) &&\n (IsHighDynamicRangeImage(image,&image->exception) != MagickFalse))\n {\n status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);\n if (status == MagickFalse)\n {\n quantum_info=DestroyQuantumInfo(quantum_info);\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n }\n }\n if ((LocaleCompare(image_info->magick,\"PTIF\") == 0) &&\n (GetPreviousImageInList(image) != (Image *) NULL))\n (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_REDUCEDIMAGE);\n if ((image->columns != (uint32) image->columns) ||\n (image->rows != (uint32) image->rows))\n ThrowWriterException(ImageError,\"WidthOrHeightExceedsLimit\");\n (void) TIFFSetField(tiff,TIFFTAG_IMAGELENGTH,(uint32) image->rows);\n (void) TIFFSetField(tiff,TIFFTAG_IMAGEWIDTH,(uint32) image->columns);\n switch (compression)\n {\n case FaxCompression:\n {\n compress_tag=COMPRESSION_CCITTFAX3;\n option=GetImageOption(image_info,\"quantum:polarity\");\n if (option == (const char *) NULL)\n SetQuantumMinIsWhite(quantum_info,MagickTrue);\n break;\n }\n case Group4Compression:\n {\n compress_tag=COMPRESSION_CCITTFAX4;\n option=GetImageOption(image_info,\"quantum:polarity\");\n if (option == (const char *) NULL)\n SetQuantumMinIsWhite(quantum_info,MagickTrue);\n break;\n }\n#if defined(COMPRESSION_JBIG)\n case JBIG1Compression:\n {\n compress_tag=COMPRESSION_JBIG;\n break;\n }\n#endif\n case JPEGCompression:\n {\n compress_tag=COMPRESSION_JPEG;\n break;\n }\n#if defined(COMPRESSION_LZMA)\n case LZMACompression:\n {\n compress_tag=COMPRESSION_LZMA;\n break;\n }\n#endif\n case LZWCompression:\n {\n compress_tag=COMPRESSION_LZW;\n break;\n }\n case RLECompression:\n {\n compress_tag=COMPRESSION_PACKBITS;\n break;\n }\n#if defined(COMPRESSION_WEBP)\n case WebPCompression:\n {\n compress_tag=COMPRESSION_WEBP;\n break;\n }\n#endif\n case ZipCompression:\n {\n compress_tag=COMPRESSION_ADOBE_DEFLATE;\n break;\n }\n#if defined(COMPRESSION_ZSTD)\n case ZstdCompression:\n {\n compress_tag=COMPRESSION_ZSTD;\n break;\n }\n#endif\n case NoCompression:\n default:\n {\n compress_tag=COMPRESSION_NONE;\n break;\n }\n }\n#if defined(MAGICKCORE_HAVE_TIFFISCODECCONFIGURED) || (TIFFLIB_VERSION > 20040919)\n if ((compress_tag != COMPRESSION_NONE) &&\n (TIFFIsCODECConfigured(compress_tag) == 0))\n {\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"CompressionNotSupported\",\"`%s'\",CommandOptionToMnemonic(\n MagickCompressOptions,(ssize_t) compression));\n compress_tag=COMPRESSION_NONE;\n }\n#else\n switch (compress_tag)\n {\n#if defined(CCITT_SUPPORT)\n case COMPRESSION_CCITTFAX3:\n case COMPRESSION_CCITTFAX4:\n#endif\n#if defined(YCBCR_SUPPORT) && defined(JPEG_SUPPORT)\n case COMPRESSION_JPEG:\n#endif\n#if defined(LZMA_SUPPORT) && defined(COMPRESSION_LZMA)\n case COMPRESSION_LZMA:\n#endif\n#if defined(LZW_SUPPORT)\n case COMPRESSION_LZW:\n#endif\n#if defined(PACKBITS_SUPPORT)\n case COMPRESSION_PACKBITS:\n#endif\n#if defined(ZIP_SUPPORT)\n case COMPRESSION_ADOBE_DEFLATE:\n#endif\n case COMPRESSION_NONE:\n break;\n default:\n {\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"CompressionNotSupported\",\"`%s'\",CommandOptionToMnemonic(\n MagickCompressOptions,(ssize_t) compression));\n compress_tag=COMPRESSION_NONE;\n break;\n }\n }\n#endif\n if (image->colorspace == CMYKColorspace)\n {\n photometric=PHOTOMETRIC_SEPARATED;\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,4);\n (void) TIFFSetField(tiff,TIFFTAG_INKSET,INKSET_CMYK);\n }\n else\n {\n /*\n Full color TIFF raster.\n */\n if (image->colorspace == LabColorspace)\n {\n photometric=PHOTOMETRIC_CIELAB;\n EncodeLabImage(image,&image->exception);\n }\n else\n if (image->colorspace == YCbCrColorspace)\n {\n photometric=PHOTOMETRIC_YCBCR;\n (void) TIFFSetField(tiff,TIFFTAG_YCBCRSUBSAMPLING,1,1);\n (void) SetImageStorageClass(image,DirectClass);\n (void) SetImageDepth(image,8);\n }\n else\n photometric=PHOTOMETRIC_RGB;\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,3);\n if ((image_info->type != TrueColorType) &&\n (image_info->type != TrueColorMatteType))\n {\n if ((image_info->type != PaletteType) &&\n (SetImageGray(image,&image->exception) != MagickFalse))\n {\n photometric=(uint16) (quantum_info->min_is_white !=\n MagickFalse ? PHOTOMETRIC_MINISWHITE :\n PHOTOMETRIC_MINISBLACK);\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,1);\n if ((image->depth == 1) && (image->matte == MagickFalse))\n SetImageMonochrome(image,&image->exception);\n }\n else\n if (image->storage_class == PseudoClass)\n {\n size_t\n depth;", " /*\n Colormapped TIFF raster.\n */\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,1);\n photometric=PHOTOMETRIC_PALETTE;\n depth=1;\n while ((GetQuantumRange(depth)+1) < image->colors)\n depth<<=1;\n status=SetQuantumDepth(image,quantum_info,depth);\n if (status == MagickFalse)\n ThrowWriterException(ResourceLimitError,\n \"MemoryAllocationFailed\");\n }\n }\n }\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_FILLORDER,&endian);\n if ((compress_tag == COMPRESSION_CCITTFAX3) ||\n (compress_tag == COMPRESSION_CCITTFAX4))\n {\n if ((photometric != PHOTOMETRIC_MINISWHITE) &&\n (photometric != PHOTOMETRIC_MINISBLACK))\n {\n compress_tag=COMPRESSION_NONE;\n endian=FILLORDER_MSB2LSB;\n }\n }\n option=GetImageOption(image_info,\"tiff:fill-order\");\n if (option != (const char *) NULL)\n {\n if (LocaleNCompare(option,\"msb\",3) == 0)\n endian=FILLORDER_MSB2LSB;\n if (LocaleNCompare(option,\"lsb\",3) == 0)\n endian=FILLORDER_LSB2MSB;\n }\n (void) TIFFSetField(tiff,TIFFTAG_COMPRESSION,compress_tag);\n (void) TIFFSetField(tiff,TIFFTAG_FILLORDER,endian);\n (void) TIFFSetField(tiff,TIFFTAG_BITSPERSAMPLE,quantum_info->depth);\n if (image->matte != MagickFalse)\n {\n uint16\n extra_samples,\n sample_info[1],\n samples_per_pixel;", " /*\n TIFF has a matte channel.\n */\n extra_samples=1;\n sample_info[0]=EXTRASAMPLE_UNASSALPHA;\n option=GetImageOption(image_info,\"tiff:alpha\");\n if (option != (const char *) NULL)\n {\n if (LocaleCompare(option,\"associated\") == 0)\n sample_info[0]=EXTRASAMPLE_ASSOCALPHA;\n else\n if (LocaleCompare(option,\"unspecified\") == 0)\n sample_info[0]=EXTRASAMPLE_UNSPECIFIED;\n }\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_SAMPLESPERPIXEL,\n &samples_per_pixel);\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLESPERPIXEL,samples_per_pixel+1);\n (void) TIFFSetField(tiff,TIFFTAG_EXTRASAMPLES,extra_samples,\n &sample_info);\n if (sample_info[0] == EXTRASAMPLE_ASSOCALPHA)\n SetQuantumAlphaType(quantum_info,AssociatedQuantumAlpha);\n }\n (void) TIFFSetField(tiff,TIFFTAG_PHOTOMETRIC,photometric);\n switch (quantum_info->format)\n {\n case FloatingPointQuantumFormat:\n {\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLEFORMAT,SAMPLEFORMAT_IEEEFP);\n (void) TIFFSetField(tiff,TIFFTAG_SMINSAMPLEVALUE,quantum_info->minimum);\n (void) TIFFSetField(tiff,TIFFTAG_SMAXSAMPLEVALUE,quantum_info->maximum);\n break;\n }\n case SignedQuantumFormat:\n {\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLEFORMAT,SAMPLEFORMAT_INT);\n break;\n }\n case UnsignedQuantumFormat:\n {\n (void) TIFFSetField(tiff,TIFFTAG_SAMPLEFORMAT,SAMPLEFORMAT_UINT);\n break;\n }\n default:\n break;\n }\n (void) TIFFSetField(tiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);\n if (photometric == PHOTOMETRIC_RGB)\n if ((image_info->interlace == PlaneInterlace) ||\n (image_info->interlace == PartitionInterlace))\n (void) TIFFSetField(tiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_SEPARATE);\n predictor=0;\n switch (compress_tag)\n {\n case COMPRESSION_JPEG:\n {\n#if defined(JPEG_SUPPORT)\n if (image_info->quality != UndefinedCompressionQuality)\n (void) TIFFSetField(tiff,TIFFTAG_JPEGQUALITY,image_info->quality);\n (void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RAW);\n if (IssRGBCompatibleColorspace(image->colorspace) != MagickFalse)\n {\n const char\n *value;", " (void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RGB);\n if (image->colorspace == YCbCrColorspace)\n {\n const char\n *sampling_factor;", " GeometryInfo\n geometry_info;", " MagickStatusType\n flags;", " sampling_factor=(const char *) NULL;\n value=GetImageProperty(image,\"jpeg:sampling-factor\");\n if (value != (char *) NULL)\n {\n sampling_factor=value;\n if (image->debug != MagickFalse)\n (void) LogMagickEvent(CoderEvent,GetMagickModule(),\n \" Input sampling-factors=%s\",sampling_factor);\n }\n if (image_info->sampling_factor != (char *) NULL)\n sampling_factor=image_info->sampling_factor;\n if (sampling_factor != (const char *) NULL)\n {\n flags=ParseGeometry(sampling_factor,&geometry_info);\n if ((flags & SigmaValue) == 0)\n geometry_info.sigma=geometry_info.rho;\n (void) TIFFSetField(tiff,TIFFTAG_YCBCRSUBSAMPLING,(uint16)\n geometry_info.rho,(uint16) geometry_info.sigma);\n }\n }\n }\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (bits_per_sample == 12)\n (void) TIFFSetField(tiff,TIFFTAG_JPEGTABLESMODE,JPEGTABLESMODE_QUANT);\n#endif\n break;\n }\n case COMPRESSION_ADOBE_DEFLATE:\n {\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n (void) TIFFSetField(tiff,TIFFTAG_ZIPQUALITY,(long) (\n image_info->quality == UndefinedCompressionQuality ? 7 :\n MagickMin((ssize_t) image_info->quality/10,9)));\n break;\n }\n case COMPRESSION_CCITTFAX3:\n {\n /*\n Byte-aligned EOL.\n */\n (void) TIFFSetField(tiff,TIFFTAG_GROUP3OPTIONS,4);\n break;\n }\n case COMPRESSION_CCITTFAX4:\n break;\n#if defined(LZMA_SUPPORT) && defined(COMPRESSION_LZMA)\n case COMPRESSION_LZMA:\n {\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n (void) TIFFSetField(tiff,TIFFTAG_LZMAPRESET,(long) (\n image_info->quality == UndefinedCompressionQuality ? 7 :\n MagickMin((ssize_t) image_info->quality/10,9)));\n break;\n }\n#endif\n case COMPRESSION_LZW:\n {\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n break;\n }\n#if defined(WEBP_SUPPORT) && defined(COMPRESSION_WEBP)\n case COMPRESSION_WEBP:\n {\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n (void) TIFFSetField(tiff,TIFFTAG_WEBP_LEVEL,mage_info->quality);\n if (image_info->quality >= 100)\n (void) TIFFSetField(tiff,TIFFTAG_WEBP_LOSSLESS,1);\n break;\n }\n#endif\n#if defined(ZSTD_SUPPORT) && defined(COMPRESSION_ZSTD)\n case COMPRESSION_ZSTD:\n {\n (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,\n &bits_per_sample);\n if (((photometric == PHOTOMETRIC_RGB) ||\n (photometric == PHOTOMETRIC_SEPARATED) ||\n (photometric == PHOTOMETRIC_MINISBLACK)) &&\n ((bits_per_sample == 8) || (bits_per_sample == 16)))\n predictor=PREDICTOR_HORIZONTAL;\n (void) TIFFSetField(tiff,TIFFTAG_ZSTD_LEVEL,22*image_info->quality/\n 100.0);\n break;\n }\n#endif\n default:\n break;\n }\n option=GetImageOption(image_info,\"tiff:predictor\");\n if (option != (const char * ) NULL)\n predictor=(size_t) strtol(option,(char **) NULL,10);\n if (predictor != 0)\n (void) TIFFSetField(tiff,TIFFTAG_PREDICTOR,predictor);\n if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))\n {\n unsigned short\n units;", " /*\n Set image resolution.\n */\n units=RESUNIT_NONE;\n if (image->units == PixelsPerInchResolution)\n units=RESUNIT_INCH;\n if (image->units == PixelsPerCentimeterResolution)\n units=RESUNIT_CENTIMETER;\n (void) TIFFSetField(tiff,TIFFTAG_RESOLUTIONUNIT,(uint16) units);\n (void) TIFFSetField(tiff,TIFFTAG_XRESOLUTION,image->x_resolution);\n (void) TIFFSetField(tiff,TIFFTAG_YRESOLUTION,image->y_resolution);\n if ((image->page.x < 0) || (image->page.y < 0))\n (void) ThrowMagickException(&image->exception,GetMagickModule(),\n CoderError,\"TIFF: negative image positions unsupported\",\"%s\",\n image->filename);\n if ((image->page.x > 0) && (image->x_resolution > 0.0))\n {\n /*\n Set horizontal image position.\n */\n (void) TIFFSetField(tiff,TIFFTAG_XPOSITION,(float) image->page.x/\n image->x_resolution);\n }\n if ((image->page.y > 0) && (image->y_resolution > 0.0))\n {\n /*\n Set vertical image position.\n */\n (void) TIFFSetField(tiff,TIFFTAG_YPOSITION,(float) image->page.y/\n image->y_resolution);\n }\n }\n if (image->chromaticity.white_point.x != 0.0)\n {\n float\n chromaticity[6];", " /*\n Set image chromaticity.\n */\n chromaticity[0]=(float) image->chromaticity.red_primary.x;\n chromaticity[1]=(float) image->chromaticity.red_primary.y;\n chromaticity[2]=(float) image->chromaticity.green_primary.x;\n chromaticity[3]=(float) image->chromaticity.green_primary.y;\n chromaticity[4]=(float) image->chromaticity.blue_primary.x;\n chromaticity[5]=(float) image->chromaticity.blue_primary.y;\n (void) TIFFSetField(tiff,TIFFTAG_PRIMARYCHROMATICITIES,chromaticity);\n chromaticity[0]=(float) image->chromaticity.white_point.x;\n chromaticity[1]=(float) image->chromaticity.white_point.y;\n (void) TIFFSetField(tiff,TIFFTAG_WHITEPOINT,chromaticity);\n }\n if ((LocaleCompare(image_info->magick,\"PTIF\") != 0) &&\n (image_info->adjoin != MagickFalse) && (imageListLength > 1))\n {\n (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE);\n if (image->scene != 0)\n (void) TIFFSetField(tiff,TIFFTAG_PAGENUMBER,(uint16) image->scene,\n imageListLength);\n }\n if (image->orientation != UndefinedOrientation)\n (void) TIFFSetField(tiff,TIFFTAG_ORIENTATION,(uint16) image->orientation);\n else\n (void) TIFFSetField(tiff,TIFFTAG_ORIENTATION,ORIENTATION_TOPLEFT);\n (void) TIFFSetProfiles(tiff,image);\n {\n uint16\n page,\n pages;", " page=(uint16) scene;\n pages=(uint16) imageListLength;\n if ((LocaleCompare(image_info->magick,\"PTIF\") != 0) &&\n (image_info->adjoin != MagickFalse) && (pages > 1))\n (void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE);\n (void) TIFFSetField(tiff,TIFFTAG_PAGENUMBER,page,pages);\n }\n (void) TIFFSetProperties(tiff,image_info,image);\nDisableMSCWarning(4127)\n if (0)\nRestoreMSCWarning\n (void) TIFFSetEXIFProperties(tiff,image);\n /*\n Write image scanlines.\n */\n if (GetTIFFInfo(image_info,tiff,&tiff_info) == MagickFalse)\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n quantum_info->endian=LSBEndian;\n pixels=GetQuantumPixels(quantum_info);\n tiff_info.scanline=GetQuantumPixels(quantum_info);\n switch (photometric)\n {\n case PHOTOMETRIC_CIELAB:\n case PHOTOMETRIC_YCBCR:\n case PHOTOMETRIC_RGB:\n {\n /*\n RGB TIFF image.\n */\n switch (image_info->interlace)\n {\n case NoInterlace:\n default:\n {\n quantum_type=RGBQuantum;\n if (image->matte != MagickFalse)\n quantum_type=RGBAQuantum;\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,quantum_type,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)\n y,image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n break;\n }\n case PlaneInterlace:\n case PartitionInterlace:\n {\n /*\n Plane interlacing: RRRRRR...GGGGGG...BBBBBB...\n */\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,RedQuantum,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)\n break;\n }\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,100,400);\n if (status == MagickFalse)\n break;\n }\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,GreenQuantum,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,1,image) == -1)\n break;\n }\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,200,400);\n if (status == MagickFalse)\n break;\n }\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,BlueQuantum,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,2,image) == -1)\n break;\n }\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,300,400);\n if (status == MagickFalse)\n break;\n }\n if (image->matte != MagickFalse)\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,\n &image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,AlphaQuantum,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,3,image) == -1)\n break;\n }\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,400,400);\n if (status == MagickFalse)\n break;\n }\n break;\n }\n }\n break;\n }\n case PHOTOMETRIC_SEPARATED:\n {\n /*\n CMYK TIFF image.\n */\n quantum_type=CMYKQuantum;\n if (image->matte != MagickFalse)\n quantum_type=CMYKAQuantum;\n if (image->colorspace != CMYKColorspace)\n (void) TransformImageColorspace(image,CMYKColorspace);\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,quantum_type,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n break;\n }\n case PHOTOMETRIC_PALETTE:\n {\n uint16\n *blue,\n *green,\n *red;", " /*\n Colormapped TIFF image.\n */\n red=(uint16 *) AcquireQuantumMemory(65536,sizeof(*red));\n green=(uint16 *) AcquireQuantumMemory(65536,sizeof(*green));\n blue=(uint16 *) AcquireQuantumMemory(65536,sizeof(*blue));\n if ((red == (uint16 *) NULL) || (green == (uint16 *) NULL) ||\n (blue == (uint16 *) NULL))\n {\n if (red != (uint16 *) NULL)\n red=(uint16 *) RelinquishMagickMemory(red);\n if (green != (uint16 *) NULL)\n green=(uint16 *) RelinquishMagickMemory(green);\n if (blue != (uint16 *) NULL)\n blue=(uint16 *) RelinquishMagickMemory(blue);\n ThrowWriterException(ResourceLimitError,\"MemoryAllocationFailed\");\n }\n /*\n Initialize TIFF colormap.\n */\n (void) memset(red,0,65536*sizeof(*red));\n (void) memset(green,0,65536*sizeof(*green));\n (void) memset(blue,0,65536*sizeof(*blue));\n for (i=0; i < (ssize_t) image->colors; i++)\n {\n red[i]=ScaleQuantumToShort(image->colormap[i].red);\n green[i]=ScaleQuantumToShort(image->colormap[i].green);\n blue[i]=ScaleQuantumToShort(image->colormap[i].blue);\n }\n (void) TIFFSetField(tiff,TIFFTAG_COLORMAP,red,green,blue);\n red=(uint16 *) RelinquishMagickMemory(red);\n green=(uint16 *) RelinquishMagickMemory(green);\n blue=(uint16 *) RelinquishMagickMemory(blue);\n }\n default:\n {\n /*\n Convert PseudoClass packets to contiguous grayscale scanlines.\n */\n quantum_type=IndexQuantum;\n if (image->matte != MagickFalse)\n {\n if (photometric != PHOTOMETRIC_PALETTE)\n quantum_type=GrayAlphaQuantum;\n else\n quantum_type=IndexAlphaQuantum;\n }\n else\n if (photometric != PHOTOMETRIC_PALETTE)\n quantum_type=GrayQuantum;\n for (y=0; y < (ssize_t) image->rows; y++)\n {\n register const PixelPacket\n *magick_restrict p;", " p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);\n if (p == (const PixelPacket *) NULL)\n break;\n (void) ExportQuantumPixels(image,(const CacheView *) NULL,\n quantum_info,quantum_type,pixels,&image->exception);\n if (TIFFWritePixels(tiff,&tiff_info,y,0,image) == -1)\n break;\n if (image->previous == (Image *) NULL)\n {\n status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,\n image->rows);\n if (status == MagickFalse)\n break;\n }\n }\n break;\n }\n }\n quantum_info=DestroyQuantumInfo(quantum_info);\n if (image->colorspace == LabColorspace)\n DecodeLabImage(image,&image->exception);\n DestroyTIFFInfo(&tiff_info);", "", "DisableMSCWarning(4127)\n if (0 && (image_info->verbose != MagickFalse))\nRestoreMSCWarning\n TIFFPrintDirectory(tiff,stdout,MagickFalse);", " if (TIFFWriteDirectory(tiff) == 0)\n {\n status=MagickFalse;\n break;\n }", " image=SyncNextImageInList(image);\n if (image == (Image *) NULL)\n break;\n status=SetImageProgress(image,SaveImagesTag,scene++,imageListLength);\n if (status == MagickFalse)\n break;\n } while (image_info->adjoin != MagickFalse);\n TIFFClose(tiff);", " return(status);", "}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 30490, "char_start": 30489, "chars": "f" }, { "char_end": 30492, "char_start": 30491, "chars": "(" }, { "char_end": 30557, "char_start": 30516, "chars": " == 0)\n {\n status=MagickFalse" }, { "char_end": 30582, "char_start": 30559, "chars": " break;\n }\n" }, { "char_end": 30864, "char_start": 30862, "chars": "tu" } ], "deleted": [ { "char_end": 30405, "char_start": 30340, "chars": " if (image->exception.severity > ErrorException)\n break;\n" }, { "char_end": 30556, "char_start": 30553, "chars": "(vo" }, { "char_end": 30559, "char_start": 30557, "chars": "d)" }, { "char_end": 30880, "char_start": 30863, "chars": "image->exception." }, { "char_end": 30886, "char_start": 30881, "chars": "everi" }, { "char_end": 30901, "char_start": 30887, "chars": "y > ErrorExcep" }, { "char_end": 30917, "char_start": 30902, "chars": "ion ? MagickFal" }, { "char_end": 30932, "char_start": 30918, "chars": "e : MagickTrue" } ] }, "commit_link": "github.com/ImageMagick/ImageMagick6/commit/3c53413eb544cc567309b4c86485eae43e956112", "file_name": "coders/tiff.c", "func_name": "WriteTIFFImage", "line_changes": { "added": [ { "char_end": 30523, "char_start": 30484, "line": " if (TIFFWriteDirectory(tiff) == 0)\n", "line_no": 897 }, { "char_end": 30531, "char_start": 30523, "line": " {\n", "line_no": 898 }, { "char_end": 30559, "char_start": 30531, "line": " status=MagickFalse;\n", "line_no": 899 }, { "char_end": 30574, "char_start": 30559, "line": " break;\n", "line_no": 900 }, { "char_end": 30582, "char_start": 30574, "line": " }\n", "line_no": 901 }, { "char_end": 30868, "char_start": 30850, "line": " return(status);\n", "line_no": 910 } ], "deleted": [ { "char_end": 30392, "char_start": 30340, "line": " if (image->exception.severity > ErrorException)\n", "line_no": 893 }, { "char_end": 30405, "char_start": 30392, "line": " break;\n", "line_no": 894 }, { "char_end": 30586, "char_start": 30549, "line": " (void) TIFFWriteDirectory(tiff);\n", "line_no": 899 }, { "char_end": 30935, "char_start": 30854, "line": " return(image->exception.severity > ErrorException ? MagickFalse : MagickTrue);\n", "line_no": 908 } ] }, "vul_type": "cwe-125" }
472
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\n\t\t\t\t struct bpf_insn *insn,\n\t\t\t\t struct bpf_reg_state *dst_reg,\n\t\t\t\t struct bpf_reg_state src_reg)\n{\n\tstruct bpf_reg_state *regs = cur_regs(env);\n\tu8 opcode = BPF_OP(insn->code);\n\tbool src_known, dst_known;\n\ts64 smin_val, smax_val;\n\tu64 umin_val, umax_val;\n\tu64 insn_bitness = (BPF_CLASS(insn->code) == BPF_ALU64) ? 64 : 32;", "", "\n\tsmin_val = src_reg.smin_value;\n\tsmax_val = src_reg.smax_value;\n\tumin_val = src_reg.umin_value;\n\tumax_val = src_reg.umax_value;\n\tsrc_known = tnum_is_const(src_reg.var_off);\n\tdst_known = tnum_is_const(dst_reg->var_off);", "\tif ((src_known && (smin_val != smax_val || umin_val != umax_val)) ||\n\t smin_val > smax_val || umin_val > umax_val) {\n\t\t/* Taint dst register if offset had invalid bounds derived from\n\t\t * e.g. dead branches.\n\t\t */\n\t\t__mark_reg_unknown(dst_reg);\n\t\treturn 0;\n\t}", "\tif (!src_known &&\n\t opcode != BPF_ADD && opcode != BPF_SUB && opcode != BPF_AND) {\n\t\t__mark_reg_unknown(dst_reg);\n\t\treturn 0;\n\t}", "\tswitch (opcode) {\n\tcase BPF_ADD:\n\t\tif (signed_add_overflows(dst_reg->smin_value, smin_val) ||\n\t\t signed_add_overflows(dst_reg->smax_value, smax_val)) {\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\tdst_reg->smin_value += smin_val;\n\t\t\tdst_reg->smax_value += smax_val;\n\t\t}\n\t\tif (dst_reg->umin_value + umin_val < umin_val ||\n\t\t dst_reg->umax_value + umax_val < umax_val) {\n\t\t\tdst_reg->umin_value = 0;\n\t\t\tdst_reg->umax_value = U64_MAX;\n\t\t} else {\n\t\t\tdst_reg->umin_value += umin_val;\n\t\t\tdst_reg->umax_value += umax_val;\n\t\t}\n\t\tdst_reg->var_off = tnum_add(dst_reg->var_off, src_reg.var_off);\n\t\tbreak;\n\tcase BPF_SUB:\n\t\tif (signed_sub_overflows(dst_reg->smin_value, smax_val) ||\n\t\t signed_sub_overflows(dst_reg->smax_value, smin_val)) {\n\t\t\t/* Overflow possible, we know nothing */\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\tdst_reg->smin_value -= smax_val;\n\t\t\tdst_reg->smax_value -= smin_val;\n\t\t}\n\t\tif (dst_reg->umin_value < umax_val) {\n\t\t\t/* Overflow possible, we know nothing */\n\t\t\tdst_reg->umin_value = 0;\n\t\t\tdst_reg->umax_value = U64_MAX;\n\t\t} else {\n\t\t\t/* Cannot overflow (as long as bounds are consistent) */\n\t\t\tdst_reg->umin_value -= umax_val;\n\t\t\tdst_reg->umax_value -= umin_val;\n\t\t}\n\t\tdst_reg->var_off = tnum_sub(dst_reg->var_off, src_reg.var_off);\n\t\tbreak;\n\tcase BPF_MUL:\n\t\tdst_reg->var_off = tnum_mul(dst_reg->var_off, src_reg.var_off);\n\t\tif (smin_val < 0 || dst_reg->smin_value < 0) {\n\t\t\t/* Ain't nobody got time to multiply that sign */\n\t\t\t__mark_reg_unbounded(dst_reg);\n\t\t\t__update_reg_bounds(dst_reg);\n\t\t\tbreak;\n\t\t}\n\t\t/* Both values are positive, so we can work with unsigned and\n\t\t * copy the result to signed (unless it exceeds S64_MAX).\n\t\t */\n\t\tif (umax_val > U32_MAX || dst_reg->umax_value > U32_MAX) {\n\t\t\t/* Potential overflow, we know nothing */\n\t\t\t__mark_reg_unbounded(dst_reg);\n\t\t\t/* (except what we can learn from the var_off) */\n\t\t\t__update_reg_bounds(dst_reg);\n\t\t\tbreak;\n\t\t}\n\t\tdst_reg->umin_value *= umin_val;\n\t\tdst_reg->umax_value *= umax_val;\n\t\tif (dst_reg->umax_value > S64_MAX) {\n\t\t\t/* Overflow possible, we know nothing */\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\tdst_reg->smin_value = dst_reg->umin_value;\n\t\t\tdst_reg->smax_value = dst_reg->umax_value;\n\t\t}\n\t\tbreak;\n\tcase BPF_AND:\n\t\tif (src_known && dst_known) {\n\t\t\t__mark_reg_known(dst_reg, dst_reg->var_off.value &\n\t\t\t\t\t\t src_reg.var_off.value);\n\t\t\tbreak;\n\t\t}\n\t\t/* We get our minimum from the var_off, since that's inherently\n\t\t * bitwise. Our maximum is the minimum of the operands' maxima.\n\t\t */\n\t\tdst_reg->var_off = tnum_and(dst_reg->var_off, src_reg.var_off);\n\t\tdst_reg->umin_value = dst_reg->var_off.value;\n\t\tdst_reg->umax_value = min(dst_reg->umax_value, umax_val);\n\t\tif (dst_reg->smin_value < 0 || smin_val < 0) {\n\t\t\t/* Lose signed bounds when ANDing negative numbers,\n\t\t\t * ain't nobody got time for that.\n\t\t\t */\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\t/* ANDing two positives gives a positive, so safe to\n\t\t\t * cast result into s64.\n\t\t\t */\n\t\t\tdst_reg->smin_value = dst_reg->umin_value;\n\t\t\tdst_reg->smax_value = dst_reg->umax_value;\n\t\t}\n\t\t/* We may learn something more from the var_off */\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tcase BPF_OR:\n\t\tif (src_known && dst_known) {\n\t\t\t__mark_reg_known(dst_reg, dst_reg->var_off.value |\n\t\t\t\t\t\t src_reg.var_off.value);\n\t\t\tbreak;\n\t\t}\n\t\t/* We get our maximum from the var_off, and our minimum is the\n\t\t * maximum of the operands' minima\n\t\t */\n\t\tdst_reg->var_off = tnum_or(dst_reg->var_off, src_reg.var_off);\n\t\tdst_reg->umin_value = max(dst_reg->umin_value, umin_val);\n\t\tdst_reg->umax_value = dst_reg->var_off.value |\n\t\t\t\t dst_reg->var_off.mask;\n\t\tif (dst_reg->smin_value < 0 || smin_val < 0) {\n\t\t\t/* Lose signed bounds when ORing negative numbers,\n\t\t\t * ain't nobody got time for that.\n\t\t\t */\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\t/* ORing two positives gives a positive, so safe to\n\t\t\t * cast result into s64.\n\t\t\t */\n\t\t\tdst_reg->smin_value = dst_reg->umin_value;\n\t\t\tdst_reg->smax_value = dst_reg->umax_value;\n\t\t}\n\t\t/* We may learn something more from the var_off */\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tcase BPF_LSH:\n\t\tif (umax_val >= insn_bitness) {\n\t\t\t/* Shifts greater than 31 or 63 are undefined.\n\t\t\t * This includes shifts by a negative number.\n\t\t\t */\n\t\t\tmark_reg_unknown(env, regs, insn->dst_reg);\n\t\t\tbreak;\n\t\t}\n\t\t/* We lose all sign bit information (except what we can pick\n\t\t * up from var_off)\n\t\t */\n\t\tdst_reg->smin_value = S64_MIN;\n\t\tdst_reg->smax_value = S64_MAX;\n\t\t/* If we might shift our top bit out, then we know nothing */\n\t\tif (dst_reg->umax_value > 1ULL << (63 - umax_val)) {\n\t\t\tdst_reg->umin_value = 0;\n\t\t\tdst_reg->umax_value = U64_MAX;\n\t\t} else {\n\t\t\tdst_reg->umin_value <<= umin_val;\n\t\t\tdst_reg->umax_value <<= umax_val;\n\t\t}\n\t\tdst_reg->var_off = tnum_lshift(dst_reg->var_off, umin_val);\n\t\t/* We may learn something more from the var_off */\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tcase BPF_RSH:\n\t\tif (umax_val >= insn_bitness) {\n\t\t\t/* Shifts greater than 31 or 63 are undefined.\n\t\t\t * This includes shifts by a negative number.\n\t\t\t */\n\t\t\tmark_reg_unknown(env, regs, insn->dst_reg);\n\t\t\tbreak;\n\t\t}\n\t\t/* BPF_RSH is an unsigned shift. If the value in dst_reg might\n\t\t * be negative, then either:\n\t\t * 1) src_reg might be zero, so the sign bit of the result is\n\t\t * unknown, so we lose our signed bounds\n\t\t * 2) it's known negative, thus the unsigned bounds capture the\n\t\t * signed bounds\n\t\t * 3) the signed bounds cross zero, so they tell us nothing\n\t\t * about the result\n\t\t * If the value in dst_reg is known nonnegative, then again the\n\t\t * unsigned bounts capture the signed bounds.\n\t\t * Thus, in all cases it suffices to blow away our signed bounds\n\t\t * and rely on inferring new ones from the unsigned bounds and\n\t\t * var_off of the result.\n\t\t */\n\t\tdst_reg->smin_value = S64_MIN;\n\t\tdst_reg->smax_value = S64_MAX;\n\t\tdst_reg->var_off = tnum_rshift(dst_reg->var_off, umin_val);\n\t\tdst_reg->umin_value >>= umax_val;\n\t\tdst_reg->umax_value >>= umin_val;\n\t\t/* We may learn something more from the var_off */\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tcase BPF_ARSH:\n\t\tif (umax_val >= insn_bitness) {\n\t\t\t/* Shifts greater than 31 or 63 are undefined.\n\t\t\t * This includes shifts by a negative number.\n\t\t\t */\n\t\t\tmark_reg_unknown(env, regs, insn->dst_reg);\n\t\t\tbreak;\n\t\t}", "\t\t/* Upon reaching here, src_known is true and\n\t\t * umax_val is equal to umin_val.\n\t\t */\n\t\tdst_reg->smin_value >>= umin_val;\n\t\tdst_reg->smax_value >>= umin_val;\n\t\tdst_reg->var_off = tnum_arshift(dst_reg->var_off, umin_val);", "\t\t/* blow away the dst_reg umin_value/umax_value and rely on\n\t\t * dst_reg var_off to refine the result.\n\t\t */\n\t\tdst_reg->umin_value = 0;\n\t\tdst_reg->umax_value = U64_MAX;\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tdefault:\n\t\tmark_reg_unknown(env, regs, insn->dst_reg);\n\t\tbreak;\n\t}", "\tif (BPF_CLASS(insn->code) != BPF_ALU64) {\n\t\t/* 32-bit ALU ops are (32,32)->32 */\n\t\tcoerce_reg_to_size(dst_reg, 4);", "\t\tcoerce_reg_to_size(&src_reg, 4);", "\t}", "\t__reg_deduce_bounds(dst_reg);\n\t__reg_bound_offset(dst_reg);\n\treturn 0;\n}" ]
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 658, "char_start": 410, "chars": "if (insn_bitness == 32) {\n\t\t/* Relevant for 32-bit RSH: Information can propagate towards\n\t\t * LSB, so it isn't sufficient to only truncate the output to\n\t\t * 32 bits.\n\t\t */\n\t\tcoerce_reg_to_size(dst_reg, 4);\n\t\tcoerce_reg_to_size(&src_reg, 4);\n\t}\n\n\t" } ], "deleted": [ { "char_end": 8112, "char_start": 8077, "chars": "_reg, 4);\n\t\tcoerce_reg_to_size(&src" } ] }, "commit_link": "github.com/torvalds/linux/commit/b799207e1e1816b09e7a5920fbb2d5fcf6edd681", "file_name": "kernel/bpf/verifier.c", "func_name": "adjust_scalar_min_max_vals", "line_changes": { "added": [ { "char_end": 436, "char_start": 409, "line": "\tif (insn_bitness == 32) {\n", "line_no": 13 }, { "char_end": 500, "char_start": 436, "line": "\t\t/* Relevant for 32-bit RSH: Information can propagate towards\n", "line_no": 14 }, { "char_end": 564, "char_start": 500, "line": "\t\t * LSB, so it isn't sufficient to only truncate the output to\n", "line_no": 15 }, { "char_end": 578, "char_start": 564, "line": "\t\t * 32 bits.\n", "line_no": 16 }, { "char_end": 584, "char_start": 578, "line": "\t\t */\n", "line_no": 17 }, { "char_end": 618, "char_start": 584, "line": "\t\tcoerce_reg_to_size(dst_reg, 4);\n", "line_no": 18 }, { "char_end": 653, "char_start": 618, "line": "\t\tcoerce_reg_to_size(&src_reg, 4);\n", "line_no": 19 }, { "char_end": 656, "char_start": 653, "line": "\t}\n", "line_no": 20 }, { "char_end": 657, "char_start": 656, "line": "\n", "line_no": 21 } ], "deleted": [ { "char_end": 8122, "char_start": 8087, "line": "\t\tcoerce_reg_to_size(&src_reg, 4);\n", "line_no": 248 } ] }, "vul_type": "cwe-125" }
473
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\n\t\t\t\t struct bpf_insn *insn,\n\t\t\t\t struct bpf_reg_state *dst_reg,\n\t\t\t\t struct bpf_reg_state src_reg)\n{\n\tstruct bpf_reg_state *regs = cur_regs(env);\n\tu8 opcode = BPF_OP(insn->code);\n\tbool src_known, dst_known;\n\ts64 smin_val, smax_val;\n\tu64 umin_val, umax_val;\n\tu64 insn_bitness = (BPF_CLASS(insn->code) == BPF_ALU64) ? 64 : 32;", "\n\tif (insn_bitness == 32) {\n\t\t/* Relevant for 32-bit RSH: Information can propagate towards\n\t\t * LSB, so it isn't sufficient to only truncate the output to\n\t\t * 32 bits.\n\t\t */\n\t\tcoerce_reg_to_size(dst_reg, 4);\n\t\tcoerce_reg_to_size(&src_reg, 4);\n\t}", "\n\tsmin_val = src_reg.smin_value;\n\tsmax_val = src_reg.smax_value;\n\tumin_val = src_reg.umin_value;\n\tumax_val = src_reg.umax_value;\n\tsrc_known = tnum_is_const(src_reg.var_off);\n\tdst_known = tnum_is_const(dst_reg->var_off);", "\tif ((src_known && (smin_val != smax_val || umin_val != umax_val)) ||\n\t smin_val > smax_val || umin_val > umax_val) {\n\t\t/* Taint dst register if offset had invalid bounds derived from\n\t\t * e.g. dead branches.\n\t\t */\n\t\t__mark_reg_unknown(dst_reg);\n\t\treturn 0;\n\t}", "\tif (!src_known &&\n\t opcode != BPF_ADD && opcode != BPF_SUB && opcode != BPF_AND) {\n\t\t__mark_reg_unknown(dst_reg);\n\t\treturn 0;\n\t}", "\tswitch (opcode) {\n\tcase BPF_ADD:\n\t\tif (signed_add_overflows(dst_reg->smin_value, smin_val) ||\n\t\t signed_add_overflows(dst_reg->smax_value, smax_val)) {\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\tdst_reg->smin_value += smin_val;\n\t\t\tdst_reg->smax_value += smax_val;\n\t\t}\n\t\tif (dst_reg->umin_value + umin_val < umin_val ||\n\t\t dst_reg->umax_value + umax_val < umax_val) {\n\t\t\tdst_reg->umin_value = 0;\n\t\t\tdst_reg->umax_value = U64_MAX;\n\t\t} else {\n\t\t\tdst_reg->umin_value += umin_val;\n\t\t\tdst_reg->umax_value += umax_val;\n\t\t}\n\t\tdst_reg->var_off = tnum_add(dst_reg->var_off, src_reg.var_off);\n\t\tbreak;\n\tcase BPF_SUB:\n\t\tif (signed_sub_overflows(dst_reg->smin_value, smax_val) ||\n\t\t signed_sub_overflows(dst_reg->smax_value, smin_val)) {\n\t\t\t/* Overflow possible, we know nothing */\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\tdst_reg->smin_value -= smax_val;\n\t\t\tdst_reg->smax_value -= smin_val;\n\t\t}\n\t\tif (dst_reg->umin_value < umax_val) {\n\t\t\t/* Overflow possible, we know nothing */\n\t\t\tdst_reg->umin_value = 0;\n\t\t\tdst_reg->umax_value = U64_MAX;\n\t\t} else {\n\t\t\t/* Cannot overflow (as long as bounds are consistent) */\n\t\t\tdst_reg->umin_value -= umax_val;\n\t\t\tdst_reg->umax_value -= umin_val;\n\t\t}\n\t\tdst_reg->var_off = tnum_sub(dst_reg->var_off, src_reg.var_off);\n\t\tbreak;\n\tcase BPF_MUL:\n\t\tdst_reg->var_off = tnum_mul(dst_reg->var_off, src_reg.var_off);\n\t\tif (smin_val < 0 || dst_reg->smin_value < 0) {\n\t\t\t/* Ain't nobody got time to multiply that sign */\n\t\t\t__mark_reg_unbounded(dst_reg);\n\t\t\t__update_reg_bounds(dst_reg);\n\t\t\tbreak;\n\t\t}\n\t\t/* Both values are positive, so we can work with unsigned and\n\t\t * copy the result to signed (unless it exceeds S64_MAX).\n\t\t */\n\t\tif (umax_val > U32_MAX || dst_reg->umax_value > U32_MAX) {\n\t\t\t/* Potential overflow, we know nothing */\n\t\t\t__mark_reg_unbounded(dst_reg);\n\t\t\t/* (except what we can learn from the var_off) */\n\t\t\t__update_reg_bounds(dst_reg);\n\t\t\tbreak;\n\t\t}\n\t\tdst_reg->umin_value *= umin_val;\n\t\tdst_reg->umax_value *= umax_val;\n\t\tif (dst_reg->umax_value > S64_MAX) {\n\t\t\t/* Overflow possible, we know nothing */\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\tdst_reg->smin_value = dst_reg->umin_value;\n\t\t\tdst_reg->smax_value = dst_reg->umax_value;\n\t\t}\n\t\tbreak;\n\tcase BPF_AND:\n\t\tif (src_known && dst_known) {\n\t\t\t__mark_reg_known(dst_reg, dst_reg->var_off.value &\n\t\t\t\t\t\t src_reg.var_off.value);\n\t\t\tbreak;\n\t\t}\n\t\t/* We get our minimum from the var_off, since that's inherently\n\t\t * bitwise. Our maximum is the minimum of the operands' maxima.\n\t\t */\n\t\tdst_reg->var_off = tnum_and(dst_reg->var_off, src_reg.var_off);\n\t\tdst_reg->umin_value = dst_reg->var_off.value;\n\t\tdst_reg->umax_value = min(dst_reg->umax_value, umax_val);\n\t\tif (dst_reg->smin_value < 0 || smin_val < 0) {\n\t\t\t/* Lose signed bounds when ANDing negative numbers,\n\t\t\t * ain't nobody got time for that.\n\t\t\t */\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\t/* ANDing two positives gives a positive, so safe to\n\t\t\t * cast result into s64.\n\t\t\t */\n\t\t\tdst_reg->smin_value = dst_reg->umin_value;\n\t\t\tdst_reg->smax_value = dst_reg->umax_value;\n\t\t}\n\t\t/* We may learn something more from the var_off */\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tcase BPF_OR:\n\t\tif (src_known && dst_known) {\n\t\t\t__mark_reg_known(dst_reg, dst_reg->var_off.value |\n\t\t\t\t\t\t src_reg.var_off.value);\n\t\t\tbreak;\n\t\t}\n\t\t/* We get our maximum from the var_off, and our minimum is the\n\t\t * maximum of the operands' minima\n\t\t */\n\t\tdst_reg->var_off = tnum_or(dst_reg->var_off, src_reg.var_off);\n\t\tdst_reg->umin_value = max(dst_reg->umin_value, umin_val);\n\t\tdst_reg->umax_value = dst_reg->var_off.value |\n\t\t\t\t dst_reg->var_off.mask;\n\t\tif (dst_reg->smin_value < 0 || smin_val < 0) {\n\t\t\t/* Lose signed bounds when ORing negative numbers,\n\t\t\t * ain't nobody got time for that.\n\t\t\t */\n\t\t\tdst_reg->smin_value = S64_MIN;\n\t\t\tdst_reg->smax_value = S64_MAX;\n\t\t} else {\n\t\t\t/* ORing two positives gives a positive, so safe to\n\t\t\t * cast result into s64.\n\t\t\t */\n\t\t\tdst_reg->smin_value = dst_reg->umin_value;\n\t\t\tdst_reg->smax_value = dst_reg->umax_value;\n\t\t}\n\t\t/* We may learn something more from the var_off */\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tcase BPF_LSH:\n\t\tif (umax_val >= insn_bitness) {\n\t\t\t/* Shifts greater than 31 or 63 are undefined.\n\t\t\t * This includes shifts by a negative number.\n\t\t\t */\n\t\t\tmark_reg_unknown(env, regs, insn->dst_reg);\n\t\t\tbreak;\n\t\t}\n\t\t/* We lose all sign bit information (except what we can pick\n\t\t * up from var_off)\n\t\t */\n\t\tdst_reg->smin_value = S64_MIN;\n\t\tdst_reg->smax_value = S64_MAX;\n\t\t/* If we might shift our top bit out, then we know nothing */\n\t\tif (dst_reg->umax_value > 1ULL << (63 - umax_val)) {\n\t\t\tdst_reg->umin_value = 0;\n\t\t\tdst_reg->umax_value = U64_MAX;\n\t\t} else {\n\t\t\tdst_reg->umin_value <<= umin_val;\n\t\t\tdst_reg->umax_value <<= umax_val;\n\t\t}\n\t\tdst_reg->var_off = tnum_lshift(dst_reg->var_off, umin_val);\n\t\t/* We may learn something more from the var_off */\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tcase BPF_RSH:\n\t\tif (umax_val >= insn_bitness) {\n\t\t\t/* Shifts greater than 31 or 63 are undefined.\n\t\t\t * This includes shifts by a negative number.\n\t\t\t */\n\t\t\tmark_reg_unknown(env, regs, insn->dst_reg);\n\t\t\tbreak;\n\t\t}\n\t\t/* BPF_RSH is an unsigned shift. If the value in dst_reg might\n\t\t * be negative, then either:\n\t\t * 1) src_reg might be zero, so the sign bit of the result is\n\t\t * unknown, so we lose our signed bounds\n\t\t * 2) it's known negative, thus the unsigned bounds capture the\n\t\t * signed bounds\n\t\t * 3) the signed bounds cross zero, so they tell us nothing\n\t\t * about the result\n\t\t * If the value in dst_reg is known nonnegative, then again the\n\t\t * unsigned bounts capture the signed bounds.\n\t\t * Thus, in all cases it suffices to blow away our signed bounds\n\t\t * and rely on inferring new ones from the unsigned bounds and\n\t\t * var_off of the result.\n\t\t */\n\t\tdst_reg->smin_value = S64_MIN;\n\t\tdst_reg->smax_value = S64_MAX;\n\t\tdst_reg->var_off = tnum_rshift(dst_reg->var_off, umin_val);\n\t\tdst_reg->umin_value >>= umax_val;\n\t\tdst_reg->umax_value >>= umin_val;\n\t\t/* We may learn something more from the var_off */\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tcase BPF_ARSH:\n\t\tif (umax_val >= insn_bitness) {\n\t\t\t/* Shifts greater than 31 or 63 are undefined.\n\t\t\t * This includes shifts by a negative number.\n\t\t\t */\n\t\t\tmark_reg_unknown(env, regs, insn->dst_reg);\n\t\t\tbreak;\n\t\t}", "\t\t/* Upon reaching here, src_known is true and\n\t\t * umax_val is equal to umin_val.\n\t\t */\n\t\tdst_reg->smin_value >>= umin_val;\n\t\tdst_reg->smax_value >>= umin_val;\n\t\tdst_reg->var_off = tnum_arshift(dst_reg->var_off, umin_val);", "\t\t/* blow away the dst_reg umin_value/umax_value and rely on\n\t\t * dst_reg var_off to refine the result.\n\t\t */\n\t\tdst_reg->umin_value = 0;\n\t\tdst_reg->umax_value = U64_MAX;\n\t\t__update_reg_bounds(dst_reg);\n\t\tbreak;\n\tdefault:\n\t\tmark_reg_unknown(env, regs, insn->dst_reg);\n\t\tbreak;\n\t}", "\tif (BPF_CLASS(insn->code) != BPF_ALU64) {\n\t\t/* 32-bit ALU ops are (32,32)->32 */\n\t\tcoerce_reg_to_size(dst_reg, 4);", "", "\t}", "\t__reg_deduce_bounds(dst_reg);\n\t__reg_bound_offset(dst_reg);\n\treturn 0;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 658, "char_start": 410, "chars": "if (insn_bitness == 32) {\n\t\t/* Relevant for 32-bit RSH: Information can propagate towards\n\t\t * LSB, so it isn't sufficient to only truncate the output to\n\t\t * 32 bits.\n\t\t */\n\t\tcoerce_reg_to_size(dst_reg, 4);\n\t\tcoerce_reg_to_size(&src_reg, 4);\n\t}\n\n\t" } ], "deleted": [ { "char_end": 8112, "char_start": 8077, "chars": "_reg, 4);\n\t\tcoerce_reg_to_size(&src" } ] }, "commit_link": "github.com/torvalds/linux/commit/b799207e1e1816b09e7a5920fbb2d5fcf6edd681", "file_name": "kernel/bpf/verifier.c", "func_name": "adjust_scalar_min_max_vals", "line_changes": { "added": [ { "char_end": 436, "char_start": 409, "line": "\tif (insn_bitness == 32) {\n", "line_no": 13 }, { "char_end": 500, "char_start": 436, "line": "\t\t/* Relevant for 32-bit RSH: Information can propagate towards\n", "line_no": 14 }, { "char_end": 564, "char_start": 500, "line": "\t\t * LSB, so it isn't sufficient to only truncate the output to\n", "line_no": 15 }, { "char_end": 578, "char_start": 564, "line": "\t\t * 32 bits.\n", "line_no": 16 }, { "char_end": 584, "char_start": 578, "line": "\t\t */\n", "line_no": 17 }, { "char_end": 618, "char_start": 584, "line": "\t\tcoerce_reg_to_size(dst_reg, 4);\n", "line_no": 18 }, { "char_end": 653, "char_start": 618, "line": "\t\tcoerce_reg_to_size(&src_reg, 4);\n", "line_no": 19 }, { "char_end": 656, "char_start": 653, "line": "\t}\n", "line_no": 20 }, { "char_end": 657, "char_start": 656, "line": "\n", "line_no": 21 } ], "deleted": [ { "char_end": 8122, "char_start": 8087, "line": "\t\tcoerce_reg_to_size(&src_reg, 4);\n", "line_no": 248 } ] }, "vul_type": "cwe-125" }
473
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb,\n\t\t\t\t int tlen, int offset)\n{\n\t__wsum csum = skb->csum;", "\tif (skb->ip_summed != CHECKSUM_COMPLETE)\n\t\treturn;\n", "\tif (offset != 0)\n\t\tcsum = csum_sub(csum,\n\t\t\t\tcsum_partial(skb_transport_header(skb) + tlen,\n\t\t\t\t\t offset, 0));", "\n\tput_cmsg(msg, SOL_IP, IP_CHECKSUM, sizeof(__wsum), &csum);\n}" ]
[ 1, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 204, "char_start": 202, "chars": " {" }, { "char_end": 219, "char_start": 207, "chars": "int tend_off" }, { "char_end": 240, "char_start": 236, "chars": "offs" }, { "char_end": 242, "char_start": 241, "chars": "t" }, { "char_end": 255, "char_start": 254, "chars": ";" }, { "char_end": 262, "char_start": 258, "chars": "csum" }, { "char_end": 264, "char_start": 263, "chars": "=" }, { "char_end": 279, "char_start": 265, "chars": "csum_sub(csum," }, { "char_end": 297, "char_start": 280, "chars": "skb_checksum(skb," }, { "char_end": 307, "char_start": 298, "chars": "tend_off," }, { "char_end": 323, "char_start": 320, "chars": "\n\t}" } ], "deleted": [ { "char_end": 209, "char_start": 205, "chars": "csum" }, { "char_end": 244, "char_start": 212, "chars": "csum_sub(csum,\n\t\t\t\tcsum_partial(" }, { "char_end": 259, "char_start": 258, "chars": "h" }, { "char_end": 264, "char_start": 260, "chars": "ader" }, { "char_end": 277, "char_start": 276, "chars": "," }, { "char_end": 283, "char_start": 280, "chars": "\t\t\t" } ] }, "commit_link": "github.com/torvalds/linux/commit/ca4ef4574f1ee5252e2cd365f8f5d5bafd048f32", "file_name": "net/ipv4/ip_sockglue.c", "func_name": "ip_cmsg_recv_checksum", "line_changes": { "added": [ { "char_end": 205, "char_start": 185, "line": "\tif (offset != 0) {\n", "line_no": 9 }, { "char_end": 256, "char_start": 205, "line": "\t\tint tend_off = skb_transport_offset(skb) + tlen;\n", "line_no": 10 }, { "char_end": 321, "char_start": 256, "line": "\t\tcsum = csum_sub(csum, skb_checksum(skb, tend_off, offset, 0));\n", "line_no": 11 }, { "char_end": 324, "char_start": 321, "line": "\t}\n", "line_no": 12 } ], "deleted": [ { "char_end": 203, "char_start": 185, "line": "\tif (offset != 0)\n", "line_no": 9 }, { "char_end": 227, "char_start": 203, "line": "\t\tcsum = csum_sub(csum,\n", "line_no": 10 }, { "char_end": 278, "char_start": 227, "line": "\t\t\t\tcsum_partial(skb_transport_header(skb) + tlen,\n", "line_no": 11 }, { "char_end": 301, "char_start": 278, "line": "\t\t\t\t\t offset, 0));\n", "line_no": 12 } ] }, "vul_type": "cwe-125" }
474
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb,\n\t\t\t\t int tlen, int offset)\n{\n\t__wsum csum = skb->csum;", "\tif (skb->ip_summed != CHECKSUM_COMPLETE)\n\t\treturn;\n", "\tif (offset != 0) {\n\t\tint tend_off = skb_transport_offset(skb) + tlen;\n\t\tcsum = csum_sub(csum, skb_checksum(skb, tend_off, offset, 0));\n\t}", "\n\tput_cmsg(msg, SOL_IP, IP_CHECKSUM, sizeof(__wsum), &csum);\n}" ]
[ 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 204, "char_start": 202, "chars": " {" }, { "char_end": 219, "char_start": 207, "chars": "int tend_off" }, { "char_end": 240, "char_start": 236, "chars": "offs" }, { "char_end": 242, "char_start": 241, "chars": "t" }, { "char_end": 255, "char_start": 254, "chars": ";" }, { "char_end": 262, "char_start": 258, "chars": "csum" }, { "char_end": 264, "char_start": 263, "chars": "=" }, { "char_end": 279, "char_start": 265, "chars": "csum_sub(csum," }, { "char_end": 297, "char_start": 280, "chars": "skb_checksum(skb," }, { "char_end": 307, "char_start": 298, "chars": "tend_off," }, { "char_end": 323, "char_start": 320, "chars": "\n\t}" } ], "deleted": [ { "char_end": 209, "char_start": 205, "chars": "csum" }, { "char_end": 244, "char_start": 212, "chars": "csum_sub(csum,\n\t\t\t\tcsum_partial(" }, { "char_end": 259, "char_start": 258, "chars": "h" }, { "char_end": 264, "char_start": 260, "chars": "ader" }, { "char_end": 277, "char_start": 276, "chars": "," }, { "char_end": 283, "char_start": 280, "chars": "\t\t\t" } ] }, "commit_link": "github.com/torvalds/linux/commit/ca4ef4574f1ee5252e2cd365f8f5d5bafd048f32", "file_name": "net/ipv4/ip_sockglue.c", "func_name": "ip_cmsg_recv_checksum", "line_changes": { "added": [ { "char_end": 205, "char_start": 185, "line": "\tif (offset != 0) {\n", "line_no": 9 }, { "char_end": 256, "char_start": 205, "line": "\t\tint tend_off = skb_transport_offset(skb) + tlen;\n", "line_no": 10 }, { "char_end": 321, "char_start": 256, "line": "\t\tcsum = csum_sub(csum, skb_checksum(skb, tend_off, offset, 0));\n", "line_no": 11 }, { "char_end": 324, "char_start": 321, "line": "\t}\n", "line_no": 12 } ], "deleted": [ { "char_end": 203, "char_start": 185, "line": "\tif (offset != 0)\n", "line_no": 9 }, { "char_end": 227, "char_start": 203, "line": "\t\tcsum = csum_sub(csum,\n", "line_no": 10 }, { "char_end": 278, "char_start": 227, "line": "\t\t\t\tcsum_partial(skb_transport_header(skb) + tlen,\n", "line_no": 11 }, { "char_end": 301, "char_start": 278, "line": "\t\t\t\t\t offset, 0));\n", "line_no": 12 } ] }, "vul_type": "cwe-125" }
474
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static bool TryParse(const char* inp, int length,\n TypedValue* buf, Variant& out,\n JSONContainerType container_type, bool is_tsimplejson) {\n SimpleParser parser(inp, length, buf, container_type, is_tsimplejson);\n bool ok = parser.parseValue();", " parser.skipSpace();\n if (!ok || parser.p != inp + length) {", " // Unsupported, malformed, or trailing garbage. Release entire stack.\n tvDecRefRange(buf, parser.top);\n return false;\n }\n out = Variant::attach(*--parser.top);\n return true;\n }" ]
[ 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 320, "char_start": 300, "chars": "if (!ok ||\n (" }, { "char_end": 339, "char_start": 338, "chars": "," }, { "char_end": 365, "char_start": 364, "chars": ")" } ], "deleted": [ { "char_end": 334, "char_start": 318, "chars": ";\n if (!ok ||" } ] }, "commit_link": "github.com/facebook/hhvm/commit/bd586671a3c22eb2f07e55f11b3ce64e1f7961e7", "file_name": "hphp/runtime/ext/json/JSON_parser.cpp", "func_name": "HPHP::SimpleParser::TryParse", "line_changes": { "added": [ { "char_end": 311, "char_start": 296, "line": " if (!ok ||\n", "line_no": 6 }, { "char_end": 369, "char_start": 311, "line": " (parser.skipSpace(), parser.p != inp + length)) {\n", "line_no": 7 } ], "deleted": [ { "char_end": 320, "char_start": 296, "line": " parser.skipSpace();\n", "line_no": 6 }, { "char_end": 363, "char_start": 320, "line": " if (!ok || parser.p != inp + length) {\n", "line_no": 7 } ] }, "vul_type": "cwe-125" }
475
cwe-125
cpp
Determine whether the {function_name} code is vulnerable or not.
[ "static bool TryParse(const char* inp, int length,\n TypedValue* buf, Variant& out,\n JSONContainerType container_type, bool is_tsimplejson) {\n SimpleParser parser(inp, length, buf, container_type, is_tsimplejson);\n bool ok = parser.parseValue();", " if (!ok ||\n (parser.skipSpace(), parser.p != inp + length)) {", " // Unsupported, malformed, or trailing garbage. Release entire stack.\n tvDecRefRange(buf, parser.top);\n return false;\n }\n out = Variant::attach(*--parser.top);\n return true;\n }" ]
[ 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 320, "char_start": 300, "chars": "if (!ok ||\n (" }, { "char_end": 339, "char_start": 338, "chars": "," }, { "char_end": 365, "char_start": 364, "chars": ")" } ], "deleted": [ { "char_end": 334, "char_start": 318, "chars": ";\n if (!ok ||" } ] }, "commit_link": "github.com/facebook/hhvm/commit/bd586671a3c22eb2f07e55f11b3ce64e1f7961e7", "file_name": "hphp/runtime/ext/json/JSON_parser.cpp", "func_name": "HPHP::SimpleParser::TryParse", "line_changes": { "added": [ { "char_end": 311, "char_start": 296, "line": " if (!ok ||\n", "line_no": 6 }, { "char_end": 369, "char_start": 311, "line": " (parser.skipSpace(), parser.p != inp + length)) {\n", "line_no": 7 } ], "deleted": [ { "char_end": 320, "char_start": 296, "line": " parser.skipSpace();\n", "line_no": 6 }, { "char_end": 363, "char_start": 320, "line": " if (!ok || parser.p != inp + length) {\n", "line_no": 7 } ] }, "vul_type": "cwe-125" }
475
cwe-125
cpp
Determine whether the {function_name} code is vulnerable or not.
[ "static inline LineContribType *_gdContributionsCalc(unsigned int line_size, unsigned int src_size, double scale_d, const interpolation_method pFilter)\n{\n\tdouble width_d;\n\tdouble scale_f_d = 1.0;\n\tconst double filter_width_d = DEFAULT_BOX_RADIUS;\n\tint windows_size;\n\tunsigned int u;\n\tLineContribType *res;", "\tif (scale_d < 1.0) {\n\t\twidth_d = filter_width_d / scale_d;\n\t\tscale_f_d = scale_d;\n\t} else {\n\t\twidth_d= filter_width_d;\n\t}", "\twindows_size = 2 * (int)ceil(width_d) + 1;\n\tres = _gdContributionsAlloc(line_size, windows_size);", "\tfor (u = 0; u < line_size; u++) {\n\t\tconst double dCenter = (double)u / scale_d;\n\t\t/* get the significant edge points affecting the pixel */\n\t\tregister int iLeft = MAX(0, (int)floor (dCenter - width_d));\n\t\tint iRight = MIN((int)ceil(dCenter + width_d), (int)src_size - 1);\n\t\tdouble dTotalWeight = 0.0;\n\t\tint iSrc;\n", "\t\tres->ContribRow[u].Left = iLeft;\n\t\tres->ContribRow[u].Right = iRight;\n", "\t\t/* Cut edge points to fit in filter window in case of spill-off */\n\t\tif (iRight - iLeft + 1 > windows_size) {\n\t\t\tif (iLeft < ((int)src_size - 1 / 2)) {\n\t\t\t\tiLeft++;\n\t\t\t} else {\n\t\t\t\tiRight--;\n\t\t\t}\n\t\t}", "", "\n\t\tfor (iSrc = iLeft; iSrc <= iRight; iSrc++) {\n\t\t\tdTotalWeight += (res->ContribRow[u].Weights[iSrc-iLeft] = scale_f_d * (*pFilter)(scale_f_d * (dCenter - (double)iSrc)));\n\t\t}", "\t\tif (dTotalWeight < 0.0) {\n\t\t\t_gdContributionsFree(res);\n\t\t\treturn NULL;\n\t\t}", "\t\tif (dTotalWeight > 0.0) {\n\t\t\tfor (iSrc = iLeft; iSrc <= iRight; iSrc++) {\n\t\t\t\tres->ContribRow[u].Weights[iSrc-iLeft] /= dTotalWeight;\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}" ]
[ 1, 1, 1, 1, 0, 1, 0, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1123, "char_start": 1050, "chars": "\n\n\t\tres->ContribRow[u].Left = iLeft;\n\t\tres->ContribRow[u].Right = iRight;" } ], "deleted": [ { "char_end": 922, "char_start": 849, "chars": "res->ContribRow[u].Left = iLeft;\n\t\tres->ContribRow[u].Right = iRight;\n\n\t\t" } ] }, "commit_link": "github.com/libgd/libgd/commit/4f65a3e4eedaffa1efcf9ee1eb08f0b504fbc31a", "file_name": "src/gd_interpolation.c", "func_name": "_gdContributionsCalc", "line_changes": { "added": [ { "char_end": 1087, "char_start": 1052, "line": "\t\tres->ContribRow[u].Left = iLeft;\n", "line_no": 37 }, { "char_end": 1124, "char_start": 1087, "line": "\t\tres->ContribRow[u].Right = iRight;\n", "line_no": 38 }, { "char_end": 1125, "char_start": 1124, "line": "\n", "line_no": 39 } ], "deleted": [ { "char_end": 882, "char_start": 847, "line": "\t\tres->ContribRow[u].Left = iLeft;\n", "line_no": 28 }, { "char_end": 919, "char_start": 882, "line": "\t\tres->ContribRow[u].Right = iRight;\n", "line_no": 29 }, { "char_end": 920, "char_start": 919, "line": "\n", "line_no": 30 } ] }, "vul_type": "cwe-125" }
476
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static inline LineContribType *_gdContributionsCalc(unsigned int line_size, unsigned int src_size, double scale_d, const interpolation_method pFilter)\n{\n\tdouble width_d;\n\tdouble scale_f_d = 1.0;\n\tconst double filter_width_d = DEFAULT_BOX_RADIUS;\n\tint windows_size;\n\tunsigned int u;\n\tLineContribType *res;", "\tif (scale_d < 1.0) {\n\t\twidth_d = filter_width_d / scale_d;\n\t\tscale_f_d = scale_d;\n\t} else {\n\t\twidth_d= filter_width_d;\n\t}", "\twindows_size = 2 * (int)ceil(width_d) + 1;\n\tres = _gdContributionsAlloc(line_size, windows_size);", "\tfor (u = 0; u < line_size; u++) {\n\t\tconst double dCenter = (double)u / scale_d;\n\t\t/* get the significant edge points affecting the pixel */\n\t\tregister int iLeft = MAX(0, (int)floor (dCenter - width_d));\n\t\tint iRight = MIN((int)ceil(dCenter + width_d), (int)src_size - 1);\n\t\tdouble dTotalWeight = 0.0;\n\t\tint iSrc;\n", "", "\t\t/* Cut edge points to fit in filter window in case of spill-off */\n\t\tif (iRight - iLeft + 1 > windows_size) {\n\t\t\tif (iLeft < ((int)src_size - 1 / 2)) {\n\t\t\t\tiLeft++;\n\t\t\t} else {\n\t\t\t\tiRight--;\n\t\t\t}\n\t\t}", "\n\t\tres->ContribRow[u].Left = iLeft;\n\t\tres->ContribRow[u].Right = iRight;", "\n\t\tfor (iSrc = iLeft; iSrc <= iRight; iSrc++) {\n\t\t\tdTotalWeight += (res->ContribRow[u].Weights[iSrc-iLeft] = scale_f_d * (*pFilter)(scale_f_d * (dCenter - (double)iSrc)));\n\t\t}", "\t\tif (dTotalWeight < 0.0) {\n\t\t\t_gdContributionsFree(res);\n\t\t\treturn NULL;\n\t\t}", "\t\tif (dTotalWeight > 0.0) {\n\t\t\tfor (iSrc = iLeft; iSrc <= iRight; iSrc++) {\n\t\t\t\tres->ContribRow[u].Weights[iSrc-iLeft] /= dTotalWeight;\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1123, "char_start": 1050, "chars": "\n\n\t\tres->ContribRow[u].Left = iLeft;\n\t\tres->ContribRow[u].Right = iRight;" } ], "deleted": [ { "char_end": 922, "char_start": 849, "chars": "res->ContribRow[u].Left = iLeft;\n\t\tres->ContribRow[u].Right = iRight;\n\n\t\t" } ] }, "commit_link": "github.com/libgd/libgd/commit/4f65a3e4eedaffa1efcf9ee1eb08f0b504fbc31a", "file_name": "src/gd_interpolation.c", "func_name": "_gdContributionsCalc", "line_changes": { "added": [ { "char_end": 1087, "char_start": 1052, "line": "\t\tres->ContribRow[u].Left = iLeft;\n", "line_no": 37 }, { "char_end": 1124, "char_start": 1087, "line": "\t\tres->ContribRow[u].Right = iRight;\n", "line_no": 38 }, { "char_end": 1125, "char_start": 1124, "line": "\n", "line_no": 39 } ], "deleted": [ { "char_end": 882, "char_start": 847, "line": "\t\tres->ContribRow[u].Left = iLeft;\n", "line_no": 28 }, { "char_end": 919, "char_start": 882, "line": "\t\tres->ContribRow[u].Right = iRight;\n", "line_no": 29 }, { "char_end": 920, "char_start": 919, "line": "\n", "line_no": 30 } ] }, "vul_type": "cwe-125" }
476
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static MagickBooleanType Get8BIMProperty(const Image *image,const char *key,\n ExceptionInfo *exception)\n{\n char\n *attribute,\n format[MagickPathExtent],\n name[MagickPathExtent],\n *resource;", " const StringInfo\n *profile;", " const unsigned char\n *info;", " long\n start,\n stop;", " MagickBooleanType\n status;", " register ssize_t\n i;", " size_t\n length;", " ssize_t\n count,\n id,\n sub_number;", " /*\n There are no newlines in path names, so it's safe as terminator.\n */\n profile=GetImageProfile(image,\"8bim\");\n if (profile == (StringInfo *) NULL)\n return(MagickFalse);\n count=(ssize_t) sscanf(key,\"8BIM:%ld,%ld:%1024[^\\n]\\n%1024[^\\n]\",&start,&stop,\n name,format);\n if ((count != 2) && (count != 3) && (count != 4))\n return(MagickFalse);\n if (count < 4)\n (void) CopyMagickString(format,\"SVG\",MagickPathExtent);\n if (count < 3)\n *name='\\0';\n sub_number=1;\n if (*name == '#')\n sub_number=(ssize_t) StringToLong(&name[1]);\n sub_number=MagickMax(sub_number,1L);\n resource=(char *) NULL;\n status=MagickFalse;\n length=GetStringInfoLength(profile);\n info=GetStringInfoDatum(profile);\n while ((length > 0) && (status == MagickFalse))\n {\n if (ReadPropertyByte(&info,&length) != (unsigned char) '8')\n continue;\n if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')\n continue;\n if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')\n continue;\n if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')\n continue;\n id=(ssize_t) ReadPropertyMSBShort(&info,&length);\n if (id < (ssize_t) start)\n continue;\n if (id > (ssize_t) stop)\n continue;\n if (resource != (char *) NULL)\n resource=DestroyString(resource);\n count=(ssize_t) ReadPropertyByte(&info,&length);\n if ((count != 0) && ((size_t) count <= length))\n {\n resource=(char *) NULL;\n if (~((size_t) count) >= (MagickPathExtent-1))\n resource=(char *) AcquireQuantumMemory((size_t) count+\n MagickPathExtent,sizeof(*resource));\n if (resource != (char *) NULL)\n {\n for (i=0; i < (ssize_t) count; i++)\n resource[i]=(char) ReadPropertyByte(&info,&length);\n resource[count]='\\0';\n }\n }\n if ((count & 0x01) == 0)\n (void) ReadPropertyByte(&info,&length);\n count=(ssize_t) ReadPropertyMSBLong(&info,&length);", "", " if ((*name != '\\0') && (*name != '#'))\n if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))\n {\n /*\n No name match, scroll forward and try next.\n */\n info+=count;\n length-=MagickMin(count,(ssize_t) length);\n continue;\n }\n if ((*name == '#') && (sub_number != 1))\n {\n /*\n No numbered match, scroll forward and try next.\n */\n sub_number--;\n info+=count;\n length-=MagickMin(count,(ssize_t) length);\n continue;\n }\n /*\n We have the resource of interest.\n */\n attribute=(char *) NULL;\n if (~((size_t) count) >= (MagickPathExtent-1))\n attribute=(char *) AcquireQuantumMemory((size_t) count+MagickPathExtent,\n sizeof(*attribute));\n if (attribute != (char *) NULL)\n {\n (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);\n attribute[count]='\\0';\n info+=count;\n length-=MagickMin(count,(ssize_t) length);\n if ((id <= 1999) || (id >= 2999))\n (void) SetImageProperty((Image *) image,key,(const char *)\n attribute,exception);\n else\n {\n char\n *path;", " if (LocaleCompare(format,\"svg\") == 0)\n path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,\n image->columns,image->rows);\n else\n path=TracePSClippath((unsigned char *) attribute,(size_t) count);\n (void) SetImageProperty((Image *) image,key,(const char *) path,\n exception);\n path=DestroyString(path);\n }\n attribute=DestroyString(attribute);\n status=MagickTrue;\n }\n }\n if (resource != (char *) NULL)\n resource=DestroyString(resource);\n return(status);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 2515, "char_start": 2412, "chars": "count < 0) || ((size_t) count > length))\n {\n length=0; \n continue;\n }\n if ((" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/dd84447b63a71fa8c3f47071b09454efc667767b", "file_name": "MagickCore/property.c", "func_name": "Get8BIMProperty", "line_changes": { "added": [ { "char_end": 2453, "char_start": 2403, "line": " if ((count < 0) || ((size_t) count > length))\n", "line_no": 90 }, { "char_end": 2461, "char_start": 2453, "line": " {\n", "line_no": 91 }, { "char_end": 2480, "char_start": 2461, "line": " length=0; \n", "line_no": 92 }, { "char_end": 2498, "char_start": 2480, "line": " continue;\n", "line_no": 93 }, { "char_end": 2506, "char_start": 2498, "line": " }\n", "line_no": 94 } ], "deleted": [] }, "vul_type": "cwe-125" }
477
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static MagickBooleanType Get8BIMProperty(const Image *image,const char *key,\n ExceptionInfo *exception)\n{\n char\n *attribute,\n format[MagickPathExtent],\n name[MagickPathExtent],\n *resource;", " const StringInfo\n *profile;", " const unsigned char\n *info;", " long\n start,\n stop;", " MagickBooleanType\n status;", " register ssize_t\n i;", " size_t\n length;", " ssize_t\n count,\n id,\n sub_number;", " /*\n There are no newlines in path names, so it's safe as terminator.\n */\n profile=GetImageProfile(image,\"8bim\");\n if (profile == (StringInfo *) NULL)\n return(MagickFalse);\n count=(ssize_t) sscanf(key,\"8BIM:%ld,%ld:%1024[^\\n]\\n%1024[^\\n]\",&start,&stop,\n name,format);\n if ((count != 2) && (count != 3) && (count != 4))\n return(MagickFalse);\n if (count < 4)\n (void) CopyMagickString(format,\"SVG\",MagickPathExtent);\n if (count < 3)\n *name='\\0';\n sub_number=1;\n if (*name == '#')\n sub_number=(ssize_t) StringToLong(&name[1]);\n sub_number=MagickMax(sub_number,1L);\n resource=(char *) NULL;\n status=MagickFalse;\n length=GetStringInfoLength(profile);\n info=GetStringInfoDatum(profile);\n while ((length > 0) && (status == MagickFalse))\n {\n if (ReadPropertyByte(&info,&length) != (unsigned char) '8')\n continue;\n if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')\n continue;\n if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')\n continue;\n if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')\n continue;\n id=(ssize_t) ReadPropertyMSBShort(&info,&length);\n if (id < (ssize_t) start)\n continue;\n if (id > (ssize_t) stop)\n continue;\n if (resource != (char *) NULL)\n resource=DestroyString(resource);\n count=(ssize_t) ReadPropertyByte(&info,&length);\n if ((count != 0) && ((size_t) count <= length))\n {\n resource=(char *) NULL;\n if (~((size_t) count) >= (MagickPathExtent-1))\n resource=(char *) AcquireQuantumMemory((size_t) count+\n MagickPathExtent,sizeof(*resource));\n if (resource != (char *) NULL)\n {\n for (i=0; i < (ssize_t) count; i++)\n resource[i]=(char) ReadPropertyByte(&info,&length);\n resource[count]='\\0';\n }\n }\n if ((count & 0x01) == 0)\n (void) ReadPropertyByte(&info,&length);\n count=(ssize_t) ReadPropertyMSBLong(&info,&length);", " if ((count < 0) || ((size_t) count > length))\n {\n length=0; \n continue;\n }", " if ((*name != '\\0') && (*name != '#'))\n if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))\n {\n /*\n No name match, scroll forward and try next.\n */\n info+=count;\n length-=MagickMin(count,(ssize_t) length);\n continue;\n }\n if ((*name == '#') && (sub_number != 1))\n {\n /*\n No numbered match, scroll forward and try next.\n */\n sub_number--;\n info+=count;\n length-=MagickMin(count,(ssize_t) length);\n continue;\n }\n /*\n We have the resource of interest.\n */\n attribute=(char *) NULL;\n if (~((size_t) count) >= (MagickPathExtent-1))\n attribute=(char *) AcquireQuantumMemory((size_t) count+MagickPathExtent,\n sizeof(*attribute));\n if (attribute != (char *) NULL)\n {\n (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);\n attribute[count]='\\0';\n info+=count;\n length-=MagickMin(count,(ssize_t) length);\n if ((id <= 1999) || (id >= 2999))\n (void) SetImageProperty((Image *) image,key,(const char *)\n attribute,exception);\n else\n {\n char\n *path;", " if (LocaleCompare(format,\"svg\") == 0)\n path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,\n image->columns,image->rows);\n else\n path=TracePSClippath((unsigned char *) attribute,(size_t) count);\n (void) SetImageProperty((Image *) image,key,(const char *) path,\n exception);\n path=DestroyString(path);\n }\n attribute=DestroyString(attribute);\n status=MagickTrue;\n }\n }\n if (resource != (char *) NULL)\n resource=DestroyString(resource);\n return(status);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 2515, "char_start": 2412, "chars": "count < 0) || ((size_t) count > length))\n {\n length=0; \n continue;\n }\n if ((" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/dd84447b63a71fa8c3f47071b09454efc667767b", "file_name": "MagickCore/property.c", "func_name": "Get8BIMProperty", "line_changes": { "added": [ { "char_end": 2453, "char_start": 2403, "line": " if ((count < 0) || ((size_t) count > length))\n", "line_no": 90 }, { "char_end": 2461, "char_start": 2453, "line": " {\n", "line_no": 91 }, { "char_end": 2480, "char_start": 2461, "line": " length=0; \n", "line_no": 92 }, { "char_end": 2498, "char_start": 2480, "line": " continue;\n", "line_no": 93 }, { "char_end": 2506, "char_start": 2498, "line": " }\n", "line_no": 94 } ], "deleted": [] }, "vul_type": "cwe-125" }
477
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static const char *parse_string(cJSON *item,const char *str,const char **ep)\n{\n\tconst char *ptr=str+1,*end_ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;\n\tif (*str!='\\\"') {*ep=str;return 0;}\t/* not a string! */", "\t\n\twhile (*end_ptr!='\\\"' && *end_ptr && ++len) if (*end_ptr++ == '\\\\') end_ptr++;\t/* Skip escaped quotes. */\n\t", "\tout=(char*)cJSON_malloc(len+1);\t/* This is how long we need for the string, roughly. */\n\tif (!out) return 0;\n\titem->valuestring=out; /* assign here so out will be deleted during cJSON_Delete() later */\n\titem->type=cJSON_String;\n\t\n\tptr=str+1;ptr2=out;\n\twhile (ptr < end_ptr)\n\t{\n\t\tif (*ptr!='\\\\') *ptr2++=*ptr++;\n\t\telse\n\t\t{\n\t\t\tptr++;\n\t\t\tswitch (*ptr)\n\t\t\t{\n\t\t\t\tcase 'b': *ptr2++='\\b';\tbreak;\n\t\t\t\tcase 'f': *ptr2++='\\f';\tbreak;\n\t\t\t\tcase 'n': *ptr2++='\\n';\tbreak;\n\t\t\t\tcase 'r': *ptr2++='\\r';\tbreak;\n\t\t\t\tcase 't': *ptr2++='\\t';\tbreak;\n\t\t\t\tcase 'u':\t /* transcode utf16 to utf8. */\n\t\t\t\t\tuc=parse_hex4(ptr+1);ptr+=4;\t/* get the unicode char. */\n\t\t\t\t\tif (ptr >= end_ptr) {*ep=str;return 0;}\t/* invalid */\n\t\t\t\t\t\n\t\t\t\t\tif ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) {*ep=str;return 0;}\t/* check for invalid. */\n\t\t\t\t\t\n\t\t\t\t\tif (uc>=0xD800 && uc<=0xDBFF)\t/* UTF16 surrogate pairs.\t*/\n\t\t\t\t\t{\n\t\t\t\t\t\tif (ptr+6 > end_ptr) {*ep=str;return 0;}\t/* invalid */\n\t\t\t\t\t\tif (ptr[1]!='\\\\' || ptr[2]!='u') {*ep=str;return 0;}\t/* missing second-half of surrogate. */\n\t\t\t\t\t\tuc2=parse_hex4(ptr+3);ptr+=6;\n\t\t\t\t\t\tif (uc2<0xDC00 || uc2>0xDFFF) {*ep=str;return 0;}\t/* invalid second-half of surrogate. */\n\t\t\t\t\t\tuc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF));\n\t\t\t\t\t}", "\t\t\t\t\tlen=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len;\n\t\t\t\t\t\n\t\t\t\t\tswitch (len) {\n\t\t\t\t\t\tcase 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;\n\t\t\t\t\t\tcase 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;\n\t\t\t\t\t\tcase 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;\n\t\t\t\t\t\tcase 1: *--ptr2 =(uc | firstByteMark[len]);\n\t\t\t\t\t}\n\t\t\t\t\tptr2+=len;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault: *ptr2++=*ptr; break;\n\t\t\t}\n\t\t\tptr++;\n\t\t}\n\t}\n\t*ptr2=0;\n\tif (*ptr=='\\\"') ptr++;\n\treturn ptr;\n}" ]
[ 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 275, "char_start": 267, "chars": "\n\t{\n\t " }, { "char_end": 301, "char_start": 299, "chars": "\n\t" }, { "char_end": 434, "char_start": 302, "chars": " {\n\t\tif (*end_ptr == '\\0')\n\t\t{\n\t\t /* prevent buffer overflow when last input character is a backslash */\n\t\t return 0;\n\t\t}\n\t\t" }, { "char_end": 482, "char_start": 473, "chars": " }\n\t}\n" } ], "deleted": [ { "char_end": 223, "char_start": 222, "chars": "\t" } ] }, "commit_link": "github.com/DaveGamble/cJSON/commit/94df772485c92866ca417d92137747b2e3b0a917", "file_name": "cJSON.c", "func_name": "parse_string", "line_changes": { "added": [ { "char_end": 223, "char_start": 222, "line": "\n", "line_no": 5 }, { "char_end": 268, "char_start": 223, "line": "\twhile (*end_ptr!='\\\"' && *end_ptr && ++len)\n", "line_no": 6 }, { "char_end": 271, "char_start": 268, "line": "\t{\n", "line_no": 7 }, { "char_end": 300, "char_start": 271, "line": "\t if (*end_ptr++ == '\\\\')\n", "line_no": 8 }, { "char_end": 307, "char_start": 300, "line": "\t {\n", "line_no": 9 }, { "char_end": 331, "char_start": 307, "line": "\t\tif (*end_ptr == '\\0')\n", "line_no": 10 }, { "char_end": 335, "char_start": 331, "line": "\t\t{\n", "line_no": 11 }, { "char_end": 412, "char_start": 335, "line": "\t\t /* prevent buffer overflow when last input character is a backslash */\n", "line_no": 12 }, { "char_end": 428, "char_start": 412, "line": "\t\t return 0;\n", "line_no": 13 }, { "char_end": 432, "char_start": 428, "line": "\t\t}\n", "line_no": 14 }, { "char_end": 472, "char_start": 432, "line": "\t\tend_ptr++;\t/* Skip escaped quotes. */\n", "line_no": 15 }, { "char_end": 479, "char_start": 472, "line": "\t }\n", "line_no": 16 }, { "char_end": 482, "char_start": 479, "line": "\t}\n", "line_no": 17 }, { "char_end": 483, "char_start": 482, "line": "\n", "line_no": 18 } ], "deleted": [ { "char_end": 224, "char_start": 222, "line": "\t\n", "line_no": 5 }, { "char_end": 331, "char_start": 224, "line": "\twhile (*end_ptr!='\\\"' && *end_ptr && ++len) if (*end_ptr++ == '\\\\') end_ptr++;\t/* Skip escaped quotes. */\n", "line_no": 6 }, { "char_end": 333, "char_start": 331, "line": "\t\n", "line_no": 7 } ] }, "vul_type": "cwe-125" }
478
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static const char *parse_string(cJSON *item,const char *str,const char **ep)\n{\n\tconst char *ptr=str+1,*end_ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;\n\tif (*str!='\\\"') {*ep=str;return 0;}\t/* not a string! */", "\n\twhile (*end_ptr!='\\\"' && *end_ptr && ++len)\n\t{\n\t if (*end_ptr++ == '\\\\')\n\t {\n\t\tif (*end_ptr == '\\0')\n\t\t{\n\t\t /* prevent buffer overflow when last input character is a backslash */\n\t\t return 0;\n\t\t}\n\t\tend_ptr++;\t/* Skip escaped quotes. */\n\t }\n\t}\n", "\tout=(char*)cJSON_malloc(len+1);\t/* This is how long we need for the string, roughly. */\n\tif (!out) return 0;\n\titem->valuestring=out; /* assign here so out will be deleted during cJSON_Delete() later */\n\titem->type=cJSON_String;\n\t\n\tptr=str+1;ptr2=out;\n\twhile (ptr < end_ptr)\n\t{\n\t\tif (*ptr!='\\\\') *ptr2++=*ptr++;\n\t\telse\n\t\t{\n\t\t\tptr++;\n\t\t\tswitch (*ptr)\n\t\t\t{\n\t\t\t\tcase 'b': *ptr2++='\\b';\tbreak;\n\t\t\t\tcase 'f': *ptr2++='\\f';\tbreak;\n\t\t\t\tcase 'n': *ptr2++='\\n';\tbreak;\n\t\t\t\tcase 'r': *ptr2++='\\r';\tbreak;\n\t\t\t\tcase 't': *ptr2++='\\t';\tbreak;\n\t\t\t\tcase 'u':\t /* transcode utf16 to utf8. */\n\t\t\t\t\tuc=parse_hex4(ptr+1);ptr+=4;\t/* get the unicode char. */\n\t\t\t\t\tif (ptr >= end_ptr) {*ep=str;return 0;}\t/* invalid */\n\t\t\t\t\t\n\t\t\t\t\tif ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) {*ep=str;return 0;}\t/* check for invalid. */\n\t\t\t\t\t\n\t\t\t\t\tif (uc>=0xD800 && uc<=0xDBFF)\t/* UTF16 surrogate pairs.\t*/\n\t\t\t\t\t{\n\t\t\t\t\t\tif (ptr+6 > end_ptr) {*ep=str;return 0;}\t/* invalid */\n\t\t\t\t\t\tif (ptr[1]!='\\\\' || ptr[2]!='u') {*ep=str;return 0;}\t/* missing second-half of surrogate. */\n\t\t\t\t\t\tuc2=parse_hex4(ptr+3);ptr+=6;\n\t\t\t\t\t\tif (uc2<0xDC00 || uc2>0xDFFF) {*ep=str;return 0;}\t/* invalid second-half of surrogate. */\n\t\t\t\t\t\tuc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF));\n\t\t\t\t\t}", "\t\t\t\t\tlen=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len;\n\t\t\t\t\t\n\t\t\t\t\tswitch (len) {\n\t\t\t\t\t\tcase 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;\n\t\t\t\t\t\tcase 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;\n\t\t\t\t\t\tcase 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;\n\t\t\t\t\t\tcase 1: *--ptr2 =(uc | firstByteMark[len]);\n\t\t\t\t\t}\n\t\t\t\t\tptr2+=len;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault: *ptr2++=*ptr; break;\n\t\t\t}\n\t\t\tptr++;\n\t\t}\n\t}\n\t*ptr2=0;\n\tif (*ptr=='\\\"') ptr++;\n\treturn ptr;\n}" ]
[ 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 275, "char_start": 267, "chars": "\n\t{\n\t " }, { "char_end": 301, "char_start": 299, "chars": "\n\t" }, { "char_end": 434, "char_start": 302, "chars": " {\n\t\tif (*end_ptr == '\\0')\n\t\t{\n\t\t /* prevent buffer overflow when last input character is a backslash */\n\t\t return 0;\n\t\t}\n\t\t" }, { "char_end": 482, "char_start": 473, "chars": " }\n\t}\n" } ], "deleted": [ { "char_end": 223, "char_start": 222, "chars": "\t" } ] }, "commit_link": "github.com/DaveGamble/cJSON/commit/94df772485c92866ca417d92137747b2e3b0a917", "file_name": "cJSON.c", "func_name": "parse_string", "line_changes": { "added": [ { "char_end": 223, "char_start": 222, "line": "\n", "line_no": 5 }, { "char_end": 268, "char_start": 223, "line": "\twhile (*end_ptr!='\\\"' && *end_ptr && ++len)\n", "line_no": 6 }, { "char_end": 271, "char_start": 268, "line": "\t{\n", "line_no": 7 }, { "char_end": 300, "char_start": 271, "line": "\t if (*end_ptr++ == '\\\\')\n", "line_no": 8 }, { "char_end": 307, "char_start": 300, "line": "\t {\n", "line_no": 9 }, { "char_end": 331, "char_start": 307, "line": "\t\tif (*end_ptr == '\\0')\n", "line_no": 10 }, { "char_end": 335, "char_start": 331, "line": "\t\t{\n", "line_no": 11 }, { "char_end": 412, "char_start": 335, "line": "\t\t /* prevent buffer overflow when last input character is a backslash */\n", "line_no": 12 }, { "char_end": 428, "char_start": 412, "line": "\t\t return 0;\n", "line_no": 13 }, { "char_end": 432, "char_start": 428, "line": "\t\t}\n", "line_no": 14 }, { "char_end": 472, "char_start": 432, "line": "\t\tend_ptr++;\t/* Skip escaped quotes. */\n", "line_no": 15 }, { "char_end": 479, "char_start": 472, "line": "\t }\n", "line_no": 16 }, { "char_end": 482, "char_start": 479, "line": "\t}\n", "line_no": 17 }, { "char_end": 483, "char_start": 482, "line": "\n", "line_no": 18 } ], "deleted": [ { "char_end": 224, "char_start": 222, "line": "\t\n", "line_no": 5 }, { "char_end": 331, "char_start": 224, "line": "\twhile (*end_ptr!='\\\"' && *end_ptr && ++len) if (*end_ptr++ == '\\\\') end_ptr++;\t/* Skip escaped quotes. */\n", "line_no": 6 }, { "char_end": 333, "char_start": 331, "line": "\t\n", "line_no": 7 } ] }, "vul_type": "cwe-125" }
478
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "dbd_st_prepare(\n SV *sth,\n imp_sth_t *imp_sth,\n char *statement,\n SV *attribs)\n{\n int i;\n SV **svp;\n dTHX;\n#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION\n#if MYSQL_VERSION_ID < CALL_PLACEHOLDER_VERSION\n char *str_ptr, *str_last_ptr;\n#if MYSQL_VERSION_ID < LIMIT_PLACEHOLDER_VERSION\n int limit_flag=0;\n#endif\n#endif", " int col_type, prepare_retval;", " MYSQL_BIND *bind, *bind_end;\n imp_sth_phb_t *fbind;\n#endif\n D_imp_xxh(sth);\n D_imp_dbh_from_sth;", " if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t-> dbd_st_prepare MYSQL_VERSION_ID %d, SQL statement: %s\\n\",\n MYSQL_VERSION_ID, statement);", "#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION\n /* Set default value of 'mysql_server_prepare' attribute for sth from dbh */\n imp_sth->use_server_side_prepare= imp_dbh->use_server_side_prepare;\n if (attribs)\n {\n svp= DBD_ATTRIB_GET_SVP(attribs, \"mysql_server_prepare\", 20);\n imp_sth->use_server_side_prepare = (svp) ?\n SvTRUE(*svp) : imp_dbh->use_server_side_prepare;", " svp = DBD_ATTRIB_GET_SVP(attribs, \"async\", 5);", " if(svp && SvTRUE(*svp)) {\n#if MYSQL_ASYNC\n imp_sth->is_async = TRUE;\n imp_sth->use_server_side_prepare = FALSE;\n#else\n do_error(sth, 2000,\n \"Async support was not built into this version of DBD::mysql\", \"HY000\");\n return 0;\n#endif\n }\n }", " imp_sth->fetch_done= 0;\n#endif", " imp_sth->done_desc= 0;\n imp_sth->result= NULL;\n imp_sth->currow= 0;", " /* Set default value of 'mysql_use_result' attribute for sth from dbh */\n svp= DBD_ATTRIB_GET_SVP(attribs, \"mysql_use_result\", 16);\n imp_sth->use_mysql_use_result= svp ?\n SvTRUE(*svp) : imp_dbh->use_mysql_use_result;", " for (i= 0; i < AV_ATTRIB_LAST; i++)\n imp_sth->av_attr[i]= Nullav;", " /*\n Clean-up previous result set(s) for sth to prevent\n 'Commands out of sync' error \n */\n mysql_st_free_result_sets(sth, imp_sth);", "#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION && MYSQL_VERSION_ID < CALL_PLACEHOLDER_VERSION\n if (imp_sth->use_server_side_prepare)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tuse_server_side_prepare set, check restrictions\\n\");\n /*\n This code is here because placeholder support is not implemented for\n statements with :-\n 1. LIMIT < 5.0.7\n 2. CALL < 5.5.3 (Added support for out & inout parameters)\n In these cases we have to disable server side prepared statements\n NOTE: These checks could cause a false positive on statements which\n include columns / table names that match \"call \" or \" limit \"\n */ \n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n#if MYSQL_VERSION_ID < LIMIT_PLACEHOLDER_VERSION\n \"\\t\\tneed to test for LIMIT & CALL\\n\");\n#else\n \"\\t\\tneed to test for restrictions\\n\");\n#endif\n str_last_ptr = statement + strlen(statement);\n for (str_ptr= statement; str_ptr < str_last_ptr; str_ptr++)\n {\n#if MYSQL_VERSION_ID < LIMIT_PLACEHOLDER_VERSION\n /*\n Place holders not supported in LIMIT's\n */\n if (limit_flag)\n {\n if (*str_ptr == '?')\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tLIMIT and ? found, set to use_server_side_prepare=0\\n\");\n /* ... then we do not want to try server side prepare (use emulation) */\n imp_sth->use_server_side_prepare= 0;\n break;\n }\n }\n else if (str_ptr < str_last_ptr - 6 &&\n isspace(*(str_ptr + 0)) &&\n tolower(*(str_ptr + 1)) == 'l' &&\n tolower(*(str_ptr + 2)) == 'i' &&\n tolower(*(str_ptr + 3)) == 'm' &&\n tolower(*(str_ptr + 4)) == 'i' &&\n tolower(*(str_ptr + 5)) == 't' &&\n isspace(*(str_ptr + 6)))\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"LIMIT set limit flag to 1\\n\");\n limit_flag= 1;\n }\n#endif\n /*\n Place holders not supported in CALL's\n */\n if (str_ptr < str_last_ptr - 4 &&\n tolower(*(str_ptr + 0)) == 'c' &&\n tolower(*(str_ptr + 1)) == 'a' &&\n tolower(*(str_ptr + 2)) == 'l' &&\n tolower(*(str_ptr + 3)) == 'l' &&\n isspace(*(str_ptr + 4)))\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"Disable PS mode for CALL()\\n\");\n imp_sth->use_server_side_prepare= 0;\n break;\n }\n }\n }\n#endif", "#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION\n if (imp_sth->use_server_side_prepare)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tuse_server_side_prepare set\\n\");\n /* do we really need this? If we do, we should return, not just continue */\n if (imp_sth->stmt)\n fprintf(stderr,\n \"ERROR: Trying to prepare new stmt while we have \\\n already not closed one \\n\");", " imp_sth->stmt= mysql_stmt_init(imp_dbh->pmysql);", " if (! imp_sth->stmt)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tERROR: Unable to return MYSQL_STMT structure \\\n from mysql_stmt_init(): ERROR NO: %d ERROR MSG:%s\\n\",\n mysql_errno(imp_dbh->pmysql),\n mysql_error(imp_dbh->pmysql));\n }", " prepare_retval= mysql_stmt_prepare(imp_sth->stmt,\n statement,\n strlen(statement));\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tmysql_stmt_prepare returned %d\\n\",\n prepare_retval);", " if (prepare_retval)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tmysql_stmt_prepare %d %s\\n\",\n mysql_stmt_errno(imp_sth->stmt),\n mysql_stmt_error(imp_sth->stmt));", " /* For commands that are not supported by server side prepared statement\n mechanism lets try to pass them through regular API */\n if (mysql_stmt_errno(imp_sth->stmt) == ER_UNSUPPORTED_PS)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tSETTING imp_sth->use_server_side_prepare to 0\\n\");\n imp_sth->use_server_side_prepare= 0;\n }\n else\n {\n do_error(sth, mysql_stmt_errno(imp_sth->stmt),\n mysql_stmt_error(imp_sth->stmt),\n mysql_sqlstate(imp_dbh->pmysql));\n mysql_stmt_close(imp_sth->stmt);\n imp_sth->stmt= NULL;\n return FALSE;\n }\n }\n else\n {\n DBIc_NUM_PARAMS(imp_sth)= mysql_stmt_param_count(imp_sth->stmt);\n /* mysql_stmt_param_count */", " if (DBIc_NUM_PARAMS(imp_sth) > 0)\n {", " int has_statement_fields= imp_sth->stmt->fields != 0;", " /* Allocate memory for bind variables */\n imp_sth->bind= alloc_bind(DBIc_NUM_PARAMS(imp_sth));\n imp_sth->fbind= alloc_fbind(DBIc_NUM_PARAMS(imp_sth));\n imp_sth->has_been_bound= 0;", " /* Initialize ph variables with NULL values */\n for (i= 0,\n bind= imp_sth->bind,\n fbind= imp_sth->fbind,\n bind_end= bind+DBIc_NUM_PARAMS(imp_sth);\n bind < bind_end ;\n bind++, fbind++, i++ )\n {", " /*\n if this statement has a result set, field types will be\n correctly identified. If there is no result set, such as\n with an INSERT, fields will not be defined, and all buffer_type\n will default to MYSQL_TYPE_VAR_STRING\n */\n col_type= (has_statement_fields ?\n imp_sth->stmt->fields[i].type : MYSQL_TYPE_STRING);", " bind->buffer_type= mysql_to_perl_type(col_type);", " if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"\\t\\tmysql_to_perl_type returned %d\\n\", col_type);\n", " bind->buffer= NULL;\n bind->length= &(fbind->length);\n bind->is_null= (char*) &(fbind->is_null);\n fbind->is_null= 1;\n fbind->length= 0;\n }\n }\n }\n }\n#endif", "#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION\n /* Count the number of parameters (driver, vs server-side) */\n if (imp_sth->use_server_side_prepare == 0)\n DBIc_NUM_PARAMS(imp_sth) = count_params((imp_xxh_t *)imp_dbh, aTHX_ statement,\n imp_dbh->bind_comment_placeholders);\n#else\n DBIc_NUM_PARAMS(imp_sth) = count_params((imp_xxh_t *)imp_dbh, aTHX_ statement,\n imp_dbh->bind_comment_placeholders);\n#endif", " /* Allocate memory for parameters */\n imp_sth->params= alloc_param(DBIc_NUM_PARAMS(imp_sth));\n DBIc_IMPSET_on(imp_sth);", " if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"\\t<- dbd_st_prepare\\n\");\n return 1;\n}" ]
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 7060, "char_start": 7060, "chars": "" }, { "char_end": 7545, "char_start": 7543, "chars": "->" } ], "deleted": [ { "char_end": 340, "char_start": 330, "chars": "col_type, " }, { "char_end": 7091, "char_start": 7029, "chars": "int has_statement_fields= imp_sth->stmt->fields != 0;\n " }, { "char_end": 7679, "char_start": 7611, "chars": "/*\n if this statement has a result set, field types will " }, { "char_end": 7704, "char_start": 7680, "chars": "e\n correctly " }, { "char_end": 7707, "char_start": 7705, "chars": "de" }, { "char_end": 7713, "char_start": 7708, "chars": "tifie" }, { "char_end": 7815, "char_start": 7714, "chars": ". If there is no result set, such as\n with an INSERT, fields will not be defined, and all " }, { "char_end": 7908, "char_start": 7826, "chars": "\n will default to MYSQL_TYPE_VAR_STRING\n */\n col_type" }, { "char_end": 7986, "char_start": 7910, "chars": "(has_statement_fields ?\n imp_sth->stmt->fields[i].type :" }, { "char_end": 8005, "char_start": 8004, "chars": ")" }, { "char_end": 8214, "char_start": 8006, "chars": "\n\n bind->buffer_type= mysql_to_perl_type(col_type);\n\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"\\t\\tmysql_to_perl_type returned %d\\n\", col_type);\n" } ] }, "commit_link": "github.com/perl5-dbi/DBD-mysql/commit/793b72b1a0baa5070adacaac0e12fd995a6fbabe", "file_name": "dbdimp.c", "func_name": "dbd_st_prepare", "line_changes": { "added": [ { "char_end": 346, "char_start": 324, "line": " int prepare_retval;\n", "line_no": 17 }, { "char_end": 7578, "char_start": 7529, "line": " bind->buffer_type= MYSQL_TYPE_STRING;\n", "line_no": 226 } ], "deleted": [ { "char_end": 356, "char_start": 324, "line": " int col_type, prepare_retval;\n", "line_no": 17 }, { "char_end": 7083, "char_start": 7021, "line": " int has_statement_fields= imp_sth->stmt->fields != 0;\n", "line_no": 213 }, { "char_end": 7614, "char_start": 7601, "line": " /*\n", "line_no": 227 }, { "char_end": 7682, "char_start": 7614, "line": " if this statement has a result set, field types will be\n", "line_no": 228 }, { "char_end": 7751, "char_start": 7682, "line": " correctly identified. If there is no result set, such as\n", "line_no": 229 }, { "char_end": 7827, "char_start": 7751, "line": " with an INSERT, fields will not be defined, and all buffer_type\n", "line_no": 230 }, { "char_end": 7877, "char_start": 7827, "line": " will default to MYSQL_TYPE_VAR_STRING\n", "line_no": 231 }, { "char_end": 7890, "char_start": 7877, "line": " */\n", "line_no": 232 }, { "char_end": 7934, "char_start": 7890, "line": " col_type= (has_statement_fields ?\n", "line_no": 233 }, { "char_end": 8007, "char_start": 7934, "line": " imp_sth->stmt->fields[i].type : MYSQL_TYPE_STRING);\n", "line_no": 234 }, { "char_end": 8008, "char_start": 8007, "line": "\n", "line_no": 235 }, { "char_end": 8068, "char_start": 8008, "line": " bind->buffer_type= mysql_to_perl_type(col_type);\n", "line_no": 236 }, { "char_end": 8069, "char_start": 8068, "line": "\n", "line_no": 237 }, { "char_end": 8115, "char_start": 8069, "line": " if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n", "line_no": 238 }, { "char_end": 8214, "char_start": 8115, "line": " PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"\\t\\tmysql_to_perl_type returned %d\\n\", col_type);\n", "line_no": 239 }, { "char_end": 8215, "char_start": 8214, "line": "\n", "line_no": 240 } ] }, "vul_type": "cwe-125" }
479
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "dbd_st_prepare(\n SV *sth,\n imp_sth_t *imp_sth,\n char *statement,\n SV *attribs)\n{\n int i;\n SV **svp;\n dTHX;\n#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION\n#if MYSQL_VERSION_ID < CALL_PLACEHOLDER_VERSION\n char *str_ptr, *str_last_ptr;\n#if MYSQL_VERSION_ID < LIMIT_PLACEHOLDER_VERSION\n int limit_flag=0;\n#endif\n#endif", " int prepare_retval;", " MYSQL_BIND *bind, *bind_end;\n imp_sth_phb_t *fbind;\n#endif\n D_imp_xxh(sth);\n D_imp_dbh_from_sth;", " if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t-> dbd_st_prepare MYSQL_VERSION_ID %d, SQL statement: %s\\n\",\n MYSQL_VERSION_ID, statement);", "#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION\n /* Set default value of 'mysql_server_prepare' attribute for sth from dbh */\n imp_sth->use_server_side_prepare= imp_dbh->use_server_side_prepare;\n if (attribs)\n {\n svp= DBD_ATTRIB_GET_SVP(attribs, \"mysql_server_prepare\", 20);\n imp_sth->use_server_side_prepare = (svp) ?\n SvTRUE(*svp) : imp_dbh->use_server_side_prepare;", " svp = DBD_ATTRIB_GET_SVP(attribs, \"async\", 5);", " if(svp && SvTRUE(*svp)) {\n#if MYSQL_ASYNC\n imp_sth->is_async = TRUE;\n imp_sth->use_server_side_prepare = FALSE;\n#else\n do_error(sth, 2000,\n \"Async support was not built into this version of DBD::mysql\", \"HY000\");\n return 0;\n#endif\n }\n }", " imp_sth->fetch_done= 0;\n#endif", " imp_sth->done_desc= 0;\n imp_sth->result= NULL;\n imp_sth->currow= 0;", " /* Set default value of 'mysql_use_result' attribute for sth from dbh */\n svp= DBD_ATTRIB_GET_SVP(attribs, \"mysql_use_result\", 16);\n imp_sth->use_mysql_use_result= svp ?\n SvTRUE(*svp) : imp_dbh->use_mysql_use_result;", " for (i= 0; i < AV_ATTRIB_LAST; i++)\n imp_sth->av_attr[i]= Nullav;", " /*\n Clean-up previous result set(s) for sth to prevent\n 'Commands out of sync' error \n */\n mysql_st_free_result_sets(sth, imp_sth);", "#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION && MYSQL_VERSION_ID < CALL_PLACEHOLDER_VERSION\n if (imp_sth->use_server_side_prepare)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tuse_server_side_prepare set, check restrictions\\n\");\n /*\n This code is here because placeholder support is not implemented for\n statements with :-\n 1. LIMIT < 5.0.7\n 2. CALL < 5.5.3 (Added support for out & inout parameters)\n In these cases we have to disable server side prepared statements\n NOTE: These checks could cause a false positive on statements which\n include columns / table names that match \"call \" or \" limit \"\n */ \n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n#if MYSQL_VERSION_ID < LIMIT_PLACEHOLDER_VERSION\n \"\\t\\tneed to test for LIMIT & CALL\\n\");\n#else\n \"\\t\\tneed to test for restrictions\\n\");\n#endif\n str_last_ptr = statement + strlen(statement);\n for (str_ptr= statement; str_ptr < str_last_ptr; str_ptr++)\n {\n#if MYSQL_VERSION_ID < LIMIT_PLACEHOLDER_VERSION\n /*\n Place holders not supported in LIMIT's\n */\n if (limit_flag)\n {\n if (*str_ptr == '?')\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tLIMIT and ? found, set to use_server_side_prepare=0\\n\");\n /* ... then we do not want to try server side prepare (use emulation) */\n imp_sth->use_server_side_prepare= 0;\n break;\n }\n }\n else if (str_ptr < str_last_ptr - 6 &&\n isspace(*(str_ptr + 0)) &&\n tolower(*(str_ptr + 1)) == 'l' &&\n tolower(*(str_ptr + 2)) == 'i' &&\n tolower(*(str_ptr + 3)) == 'm' &&\n tolower(*(str_ptr + 4)) == 'i' &&\n tolower(*(str_ptr + 5)) == 't' &&\n isspace(*(str_ptr + 6)))\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"LIMIT set limit flag to 1\\n\");\n limit_flag= 1;\n }\n#endif\n /*\n Place holders not supported in CALL's\n */\n if (str_ptr < str_last_ptr - 4 &&\n tolower(*(str_ptr + 0)) == 'c' &&\n tolower(*(str_ptr + 1)) == 'a' &&\n tolower(*(str_ptr + 2)) == 'l' &&\n tolower(*(str_ptr + 3)) == 'l' &&\n isspace(*(str_ptr + 4)))\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"Disable PS mode for CALL()\\n\");\n imp_sth->use_server_side_prepare= 0;\n break;\n }\n }\n }\n#endif", "#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION\n if (imp_sth->use_server_side_prepare)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tuse_server_side_prepare set\\n\");\n /* do we really need this? If we do, we should return, not just continue */\n if (imp_sth->stmt)\n fprintf(stderr,\n \"ERROR: Trying to prepare new stmt while we have \\\n already not closed one \\n\");", " imp_sth->stmt= mysql_stmt_init(imp_dbh->pmysql);", " if (! imp_sth->stmt)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tERROR: Unable to return MYSQL_STMT structure \\\n from mysql_stmt_init(): ERROR NO: %d ERROR MSG:%s\\n\",\n mysql_errno(imp_dbh->pmysql),\n mysql_error(imp_dbh->pmysql));\n }", " prepare_retval= mysql_stmt_prepare(imp_sth->stmt,\n statement,\n strlen(statement));\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tmysql_stmt_prepare returned %d\\n\",\n prepare_retval);", " if (prepare_retval)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tmysql_stmt_prepare %d %s\\n\",\n mysql_stmt_errno(imp_sth->stmt),\n mysql_stmt_error(imp_sth->stmt));", " /* For commands that are not supported by server side prepared statement\n mechanism lets try to pass them through regular API */\n if (mysql_stmt_errno(imp_sth->stmt) == ER_UNSUPPORTED_PS)\n {\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh),\n \"\\t\\tSETTING imp_sth->use_server_side_prepare to 0\\n\");\n imp_sth->use_server_side_prepare= 0;\n }\n else\n {\n do_error(sth, mysql_stmt_errno(imp_sth->stmt),\n mysql_stmt_error(imp_sth->stmt),\n mysql_sqlstate(imp_dbh->pmysql));\n mysql_stmt_close(imp_sth->stmt);\n imp_sth->stmt= NULL;\n return FALSE;\n }\n }\n else\n {\n DBIc_NUM_PARAMS(imp_sth)= mysql_stmt_param_count(imp_sth->stmt);\n /* mysql_stmt_param_count */", " if (DBIc_NUM_PARAMS(imp_sth) > 0)\n {", "", " /* Allocate memory for bind variables */\n imp_sth->bind= alloc_bind(DBIc_NUM_PARAMS(imp_sth));\n imp_sth->fbind= alloc_fbind(DBIc_NUM_PARAMS(imp_sth));\n imp_sth->has_been_bound= 0;", " /* Initialize ph variables with NULL values */\n for (i= 0,\n bind= imp_sth->bind,\n fbind= imp_sth->fbind,\n bind_end= bind+DBIc_NUM_PARAMS(imp_sth);\n bind < bind_end ;\n bind++, fbind++, i++ )\n {", " bind->buffer_type= MYSQL_TYPE_STRING;", " bind->buffer= NULL;\n bind->length= &(fbind->length);\n bind->is_null= (char*) &(fbind->is_null);\n fbind->is_null= 1;\n fbind->length= 0;\n }\n }\n }\n }\n#endif", "#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION\n /* Count the number of parameters (driver, vs server-side) */\n if (imp_sth->use_server_side_prepare == 0)\n DBIc_NUM_PARAMS(imp_sth) = count_params((imp_xxh_t *)imp_dbh, aTHX_ statement,\n imp_dbh->bind_comment_placeholders);\n#else\n DBIc_NUM_PARAMS(imp_sth) = count_params((imp_xxh_t *)imp_dbh, aTHX_ statement,\n imp_dbh->bind_comment_placeholders);\n#endif", " /* Allocate memory for parameters */\n imp_sth->params= alloc_param(DBIc_NUM_PARAMS(imp_sth));\n DBIc_IMPSET_on(imp_sth);", " if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"\\t<- dbd_st_prepare\\n\");\n return 1;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 7060, "char_start": 7060, "chars": "" }, { "char_end": 7545, "char_start": 7543, "chars": "->" } ], "deleted": [ { "char_end": 340, "char_start": 330, "chars": "col_type, " }, { "char_end": 7091, "char_start": 7029, "chars": "int has_statement_fields= imp_sth->stmt->fields != 0;\n " }, { "char_end": 7679, "char_start": 7611, "chars": "/*\n if this statement has a result set, field types will " }, { "char_end": 7704, "char_start": 7680, "chars": "e\n correctly " }, { "char_end": 7707, "char_start": 7705, "chars": "de" }, { "char_end": 7713, "char_start": 7708, "chars": "tifie" }, { "char_end": 7815, "char_start": 7714, "chars": ". If there is no result set, such as\n with an INSERT, fields will not be defined, and all " }, { "char_end": 7908, "char_start": 7826, "chars": "\n will default to MYSQL_TYPE_VAR_STRING\n */\n col_type" }, { "char_end": 7986, "char_start": 7910, "chars": "(has_statement_fields ?\n imp_sth->stmt->fields[i].type :" }, { "char_end": 8005, "char_start": 8004, "chars": ")" }, { "char_end": 8214, "char_start": 8006, "chars": "\n\n bind->buffer_type= mysql_to_perl_type(col_type);\n\n if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"\\t\\tmysql_to_perl_type returned %d\\n\", col_type);\n" } ] }, "commit_link": "github.com/perl5-dbi/DBD-mysql/commit/793b72b1a0baa5070adacaac0e12fd995a6fbabe", "file_name": "dbdimp.c", "func_name": "dbd_st_prepare", "line_changes": { "added": [ { "char_end": 346, "char_start": 324, "line": " int prepare_retval;\n", "line_no": 17 }, { "char_end": 7578, "char_start": 7529, "line": " bind->buffer_type= MYSQL_TYPE_STRING;\n", "line_no": 226 } ], "deleted": [ { "char_end": 356, "char_start": 324, "line": " int col_type, prepare_retval;\n", "line_no": 17 }, { "char_end": 7083, "char_start": 7021, "line": " int has_statement_fields= imp_sth->stmt->fields != 0;\n", "line_no": 213 }, { "char_end": 7614, "char_start": 7601, "line": " /*\n", "line_no": 227 }, { "char_end": 7682, "char_start": 7614, "line": " if this statement has a result set, field types will be\n", "line_no": 228 }, { "char_end": 7751, "char_start": 7682, "line": " correctly identified. If there is no result set, such as\n", "line_no": 229 }, { "char_end": 7827, "char_start": 7751, "line": " with an INSERT, fields will not be defined, and all buffer_type\n", "line_no": 230 }, { "char_end": 7877, "char_start": 7827, "line": " will default to MYSQL_TYPE_VAR_STRING\n", "line_no": 231 }, { "char_end": 7890, "char_start": 7877, "line": " */\n", "line_no": 232 }, { "char_end": 7934, "char_start": 7890, "line": " col_type= (has_statement_fields ?\n", "line_no": 233 }, { "char_end": 8007, "char_start": 7934, "line": " imp_sth->stmt->fields[i].type : MYSQL_TYPE_STRING);\n", "line_no": 234 }, { "char_end": 8008, "char_start": 8007, "line": "\n", "line_no": 235 }, { "char_end": 8068, "char_start": 8008, "line": " bind->buffer_type= mysql_to_perl_type(col_type);\n", "line_no": 236 }, { "char_end": 8069, "char_start": 8068, "line": "\n", "line_no": 237 }, { "char_end": 8115, "char_start": 8069, "line": " if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)\n", "line_no": 238 }, { "char_end": 8214, "char_start": 8115, "line": " PerlIO_printf(DBIc_LOGPIO(imp_xxh), \"\\t\\tmysql_to_perl_type returned %d\\n\", col_type);\n", "line_no": 239 }, { "char_end": 8215, "char_start": 8214, "line": "\n", "line_no": 240 } ] }, "vul_type": "cwe-125" }
479
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "get_uncompressed_data(struct archive_read *a, const void **buff, size_t size,\n size_t minimum)\n{\n\tstruct _7zip *zip = (struct _7zip *)a->format->data;\n\tssize_t bytes_avail;", "\tif (zip->codec == _7Z_COPY && zip->codec2 == (unsigned long)-1) {\n\t\t/* Copy mode. */\n", "\t\t/*\n\t\t * Note: '1' here is a performance optimization.\n\t\t * Recall that the decompression layer returns a count of\n\t\t * available bytes; asking for more than that forces the\n\t\t * decompressor to combine reads by copying data.\n\t\t */\n\t\t*buff = __archive_read_ahead(a, 1, &bytes_avail);", "\t\tif (bytes_avail <= 0) {\n\t\t\tarchive_set_error(&a->archive,\n\t\t\t ARCHIVE_ERRNO_FILE_FORMAT,\n\t\t\t \"Truncated 7-Zip file data\");\n\t\t\treturn (ARCHIVE_FATAL);\n\t\t}\n\t\tif ((size_t)bytes_avail >\n\t\t zip->uncompressed_buffer_bytes_remaining)\n\t\t\tbytes_avail = (ssize_t)\n\t\t\t zip->uncompressed_buffer_bytes_remaining;\n\t\tif ((size_t)bytes_avail > size)\n\t\t\tbytes_avail = (ssize_t)size;", "\t\tzip->pack_stream_bytes_unconsumed = bytes_avail;\n\t} else if (zip->uncompressed_buffer_pointer == NULL) {\n\t\t/* Decompression has failed. */\n\t\tarchive_set_error(&(a->archive),\n\t\t ARCHIVE_ERRNO_MISC, \"Damaged 7-Zip archive\");\n\t\treturn (ARCHIVE_FATAL);\n\t} else {\n\t\t/* Packed mode. */\n\t\tif (minimum > zip->uncompressed_buffer_bytes_remaining) {\n\t\t\t/*\n\t\t\t * If remaining uncompressed data size is less than\n\t\t\t * the minimum size, fill the buffer up to the\n\t\t\t * minimum size.\n\t\t\t */\n\t\t\tif (extract_pack_stream(a, minimum) < 0)\n\t\t\t\treturn (ARCHIVE_FATAL);\n\t\t}\n\t\tif (size > zip->uncompressed_buffer_bytes_remaining)\n\t\t\tbytes_avail = (ssize_t)\n\t\t\t zip->uncompressed_buffer_bytes_remaining;\n\t\telse\n\t\t\tbytes_avail = (ssize_t)size;\n\t\t*buff = zip->uncompressed_buffer_pointer;\n\t\tzip->uncompressed_buffer_pointer += bytes_avail;\n\t}\n\tzip->uncompressed_buffer_bytes_remaining -= bytes_avail;\n\treturn (bytes_avail);\n}" ]
[ 1, 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 305, "char_start": 298, "chars": "minimum" } ], "deleted": [ { "char_end": 499, "char_start": 266, "chars": "/*\n\t\t * Note: '1' here is a performance optimization.\n\t\t * Recall that the decompression layer returns a count of\n\t\t * available bytes; asking for more than that forces the\n\t\t * decompressor to combine reads by copying data.\n\t\t */\n\t\t" }, { "char_end": 532, "char_start": 531, "chars": "1" } ] }, "commit_link": "github.com/libarchive/libarchive/commit/65a23f5dbee4497064e9bb467f81138a62b0dae1", "file_name": "libarchive/archive_read_support_format_7zip.c", "func_name": "get_uncompressed_data", "line_changes": { "added": [ { "char_end": 322, "char_start": 264, "line": "\t\t*buff = __archive_read_ahead(a, minimum, &bytes_avail);\n", "line_no": 10 } ], "deleted": [ { "char_end": 269, "char_start": 264, "line": "\t\t/*\n", "line_no": 10 }, { "char_end": 320, "char_start": 269, "line": "\t\t * Note: '1' here is a performance optimization.\n", "line_no": 11 }, { "char_end": 380, "char_start": 320, "line": "\t\t * Recall that the decompression layer returns a count of\n", "line_no": 12 }, { "char_end": 439, "char_start": 380, "line": "\t\t * available bytes; asking for more than that forces the\n", "line_no": 13 }, { "char_end": 491, "char_start": 439, "line": "\t\t * decompressor to combine reads by copying data.\n", "line_no": 14 }, { "char_end": 497, "char_start": 491, "line": "\t\t */\n", "line_no": 15 }, { "char_end": 549, "char_start": 497, "line": "\t\t*buff = __archive_read_ahead(a, 1, &bytes_avail);\n", "line_no": 16 } ] }, "vul_type": "cwe-125" }
480
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "get_uncompressed_data(struct archive_read *a, const void **buff, size_t size,\n size_t minimum)\n{\n\tstruct _7zip *zip = (struct _7zip *)a->format->data;\n\tssize_t bytes_avail;", "\tif (zip->codec == _7Z_COPY && zip->codec2 == (unsigned long)-1) {\n\t\t/* Copy mode. */\n", "\t\t*buff = __archive_read_ahead(a, minimum, &bytes_avail);", "\t\tif (bytes_avail <= 0) {\n\t\t\tarchive_set_error(&a->archive,\n\t\t\t ARCHIVE_ERRNO_FILE_FORMAT,\n\t\t\t \"Truncated 7-Zip file data\");\n\t\t\treturn (ARCHIVE_FATAL);\n\t\t}\n\t\tif ((size_t)bytes_avail >\n\t\t zip->uncompressed_buffer_bytes_remaining)\n\t\t\tbytes_avail = (ssize_t)\n\t\t\t zip->uncompressed_buffer_bytes_remaining;\n\t\tif ((size_t)bytes_avail > size)\n\t\t\tbytes_avail = (ssize_t)size;", "\t\tzip->pack_stream_bytes_unconsumed = bytes_avail;\n\t} else if (zip->uncompressed_buffer_pointer == NULL) {\n\t\t/* Decompression has failed. */\n\t\tarchive_set_error(&(a->archive),\n\t\t ARCHIVE_ERRNO_MISC, \"Damaged 7-Zip archive\");\n\t\treturn (ARCHIVE_FATAL);\n\t} else {\n\t\t/* Packed mode. */\n\t\tif (minimum > zip->uncompressed_buffer_bytes_remaining) {\n\t\t\t/*\n\t\t\t * If remaining uncompressed data size is less than\n\t\t\t * the minimum size, fill the buffer up to the\n\t\t\t * minimum size.\n\t\t\t */\n\t\t\tif (extract_pack_stream(a, minimum) < 0)\n\t\t\t\treturn (ARCHIVE_FATAL);\n\t\t}\n\t\tif (size > zip->uncompressed_buffer_bytes_remaining)\n\t\t\tbytes_avail = (ssize_t)\n\t\t\t zip->uncompressed_buffer_bytes_remaining;\n\t\telse\n\t\t\tbytes_avail = (ssize_t)size;\n\t\t*buff = zip->uncompressed_buffer_pointer;\n\t\tzip->uncompressed_buffer_pointer += bytes_avail;\n\t}\n\tzip->uncompressed_buffer_bytes_remaining -= bytes_avail;\n\treturn (bytes_avail);\n}" ]
[ 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 305, "char_start": 298, "chars": "minimum" } ], "deleted": [ { "char_end": 499, "char_start": 266, "chars": "/*\n\t\t * Note: '1' here is a performance optimization.\n\t\t * Recall that the decompression layer returns a count of\n\t\t * available bytes; asking for more than that forces the\n\t\t * decompressor to combine reads by copying data.\n\t\t */\n\t\t" }, { "char_end": 532, "char_start": 531, "chars": "1" } ] }, "commit_link": "github.com/libarchive/libarchive/commit/65a23f5dbee4497064e9bb467f81138a62b0dae1", "file_name": "libarchive/archive_read_support_format_7zip.c", "func_name": "get_uncompressed_data", "line_changes": { "added": [ { "char_end": 322, "char_start": 264, "line": "\t\t*buff = __archive_read_ahead(a, minimum, &bytes_avail);\n", "line_no": 10 } ], "deleted": [ { "char_end": 269, "char_start": 264, "line": "\t\t/*\n", "line_no": 10 }, { "char_end": 320, "char_start": 269, "line": "\t\t * Note: '1' here is a performance optimization.\n", "line_no": 11 }, { "char_end": 380, "char_start": 320, "line": "\t\t * Recall that the decompression layer returns a count of\n", "line_no": 12 }, { "char_end": 439, "char_start": 380, "line": "\t\t * available bytes; asking for more than that forces the\n", "line_no": 13 }, { "char_end": 491, "char_start": 439, "line": "\t\t * decompressor to combine reads by copying data.\n", "line_no": 14 }, { "char_end": 497, "char_start": 491, "line": "\t\t */\n", "line_no": 15 }, { "char_end": 549, "char_start": 497, "line": "\t\t*buff = __archive_read_ahead(a, 1, &bytes_avail);\n", "line_no": 16 } ] }, "vul_type": "cwe-125" }
480
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "BOOL security_fips_decrypt(BYTE* data, size_t length, rdpRdp* rdp)\n{\n\tsize_t olen;", "", "\n\tif (!winpr_Cipher_Update(rdp->fips_decrypt, data, length, data, &olen))\n\t\treturn FALSE;", "\treturn TRUE;\n}" ]
[ 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 140, "char_start": 90, "chars": "rdp || !rdp->fips_decrypt)\n\t\treturn FALSE;\n\n\tif (!" } ], "deleted": [] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/d6cd14059b257318f176c0ba3ee0a348826a9ef8", "file_name": "libfreerdp/core/security.c", "func_name": "security_fips_decrypt", "line_changes": { "added": [ { "char_end": 117, "char_start": 84, "line": "\tif (!rdp || !rdp->fips_decrypt)\n", "line_no": 5 }, { "char_end": 133, "char_start": 117, "line": "\t\treturn FALSE;\n", "line_no": 6 }, { "char_end": 134, "char_start": 133, "line": "\n", "line_no": 7 } ], "deleted": [] }, "vul_type": "cwe-125" }
481
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "BOOL security_fips_decrypt(BYTE* data, size_t length, rdpRdp* rdp)\n{\n\tsize_t olen;", "\n\tif (!rdp || !rdp->fips_decrypt)\n\t\treturn FALSE;", "\n\tif (!winpr_Cipher_Update(rdp->fips_decrypt, data, length, data, &olen))\n\t\treturn FALSE;", "\treturn TRUE;\n}" ]
[ 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 140, "char_start": 90, "chars": "rdp || !rdp->fips_decrypt)\n\t\treturn FALSE;\n\n\tif (!" } ], "deleted": [] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/d6cd14059b257318f176c0ba3ee0a348826a9ef8", "file_name": "libfreerdp/core/security.c", "func_name": "security_fips_decrypt", "line_changes": { "added": [ { "char_end": 117, "char_start": 84, "line": "\tif (!rdp || !rdp->fips_decrypt)\n", "line_no": 5 }, { "char_end": 133, "char_start": 117, "line": "\t\treturn FALSE;\n", "line_no": 6 }, { "char_end": 134, "char_start": 133, "line": "\n", "line_no": 7 } ], "deleted": [] }, "vul_type": "cwe-125" }
481
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static BOOL update_read_icon_info(wStream* s, ICON_INFO* iconInfo)\n{\n\tBYTE* newBitMask;", "\tif (Stream_GetRemainingLength(s) < 8)\n\t\treturn FALSE;", "\tStream_Read_UINT16(s, iconInfo->cacheEntry); /* cacheEntry (2 bytes) */\n\tStream_Read_UINT8(s, iconInfo->cacheId); /* cacheId (1 byte) */\n\tStream_Read_UINT8(s, iconInfo->bpp); /* bpp (1 byte) */", "\tif ((iconInfo->bpp < 1) || (iconInfo->bpp > 32))\n\t{\n\t\tWLog_ERR(TAG, \"invalid bpp value %\" PRIu32 \"\", iconInfo->bpp);\n\t\treturn FALSE;\n\t}", "\tStream_Read_UINT16(s, iconInfo->width); /* width (2 bytes) */\n\tStream_Read_UINT16(s, iconInfo->height); /* height (2 bytes) */", "\t/* cbColorTable is only present when bpp is 1, 4 or 8 */\n\tswitch (iconInfo->bpp)\n\t{\n\t\tcase 1:\n\t\tcase 4:\n\t\tcase 8:\n\t\t\tif (Stream_GetRemainingLength(s) < 2)\n\t\t\t\treturn FALSE;", "\t\t\tStream_Read_UINT16(s, iconInfo->cbColorTable); /* cbColorTable (2 bytes) */\n\t\t\tbreak;", "\t\tdefault:\n\t\t\ticonInfo->cbColorTable = 0;\n\t\t\tbreak;\n\t}", "\tif (Stream_GetRemainingLength(s) < 4)\n\t\treturn FALSE;", "\tStream_Read_UINT16(s, iconInfo->cbBitsMask); /* cbBitsMask (2 bytes) */\n\tStream_Read_UINT16(s, iconInfo->cbBitsColor); /* cbBitsColor (2 bytes) */\n", "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask + iconInfo->cbBitsColor)\n\t\treturn FALSE;\n", "\t/* bitsMask */\n\tnewBitMask = (BYTE*)realloc(iconInfo->bitsMask, iconInfo->cbBitsMask);", "\tif (!newBitMask)\n\t{\n\t\tfree(iconInfo->bitsMask);\n\t\ticonInfo->bitsMask = NULL;\n\t\treturn FALSE;\n\t}", "\ticonInfo->bitsMask = newBitMask;", "", "\tStream_Read(s, iconInfo->bitsMask, iconInfo->cbBitsMask);", "\t/* colorTable */\n\tif (iconInfo->colorTable == NULL)\n\t{\n\t\tif (iconInfo->cbColorTable)\n\t\t{\n\t\t\ticonInfo->colorTable = (BYTE*)malloc(iconInfo->cbColorTable);", "\t\t\tif (!iconInfo->colorTable)\n\t\t\t\treturn FALSE;\n\t\t}\n\t}\n\telse if (iconInfo->cbColorTable)\n\t{\n\t\tBYTE* new_tab;\n\t\tnew_tab = (BYTE*)realloc(iconInfo->colorTable, iconInfo->cbColorTable);", "\t\tif (!new_tab)\n\t\t{\n\t\t\tfree(iconInfo->colorTable);\n\t\t\ticonInfo->colorTable = NULL;\n\t\t\treturn FALSE;\n\t\t}", "\t\ticonInfo->colorTable = new_tab;\n\t}\n\telse\n\t{\n\t\tfree(iconInfo->colorTable);\n\t\ticonInfo->colorTable = NULL;\n\t}", "\tif (iconInfo->colorTable)", "", "\t\tStream_Read(s, iconInfo->colorTable, iconInfo->cbColorTable);", "", "\n\t/* bitsColor */\n\tnewBitMask = (BYTE*)realloc(iconInfo->bitsColor, iconInfo->cbBitsColor);", "\tif (!newBitMask)\n\t{\n\t\tfree(iconInfo->bitsColor);\n\t\ticonInfo->bitsColor = NULL;\n\t\treturn FALSE;\n\t}", "\ticonInfo->bitsColor = newBitMask;", "", "\tStream_Read(s, iconInfo->bitsColor, iconInfo->cbBitsColor);\n\treturn TRUE;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1164, "char_start": 1164, "chars": "" }, { "char_end": 1443, "char_start": 1369, "chars": "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask)\n\t\treturn FALSE;\n" }, { "char_end": 2167, "char_start": 2086, "chars": "\t{\n\t\tif (Stream_GetRemainingLength(s) < iconInfo->cbColorTable)\n\t\t\treturn FALSE;\n" }, { "char_end": 2233, "char_start": 2230, "chars": "\n\t}" }, { "char_end": 2535, "char_start": 2460, "chars": ";\n\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsColor)\n\t\treturn FALSE" } ], "deleted": [ { "char_end": 1248, "char_start": 1149, "chars": "if (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask + iconInfo->cbBitsColor)\n\t\treturn FALSE;\n\n\t" }, { "char_end": 2368, "char_start": 2368, "chars": "" } ] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/6b2bc41935e53b0034fe5948aeeab4f32e80f30f", "file_name": "libfreerdp/core/window.c", "func_name": "update_read_icon_info", "line_changes": { "added": [ { "char_end": 1427, "char_start": 1369, "line": "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask)\n", "line_no": 55 }, { "char_end": 1443, "char_start": 1427, "line": "\t\treturn FALSE;\n", "line_no": 56 }, { "char_end": 2089, "char_start": 2086, "line": "\t{\n", "line_no": 91 }, { "char_end": 2150, "char_start": 2089, "line": "\t\tif (Stream_GetRemainingLength(s) < iconInfo->cbColorTable)\n", "line_no": 92 }, { "char_end": 2167, "char_start": 2150, "line": "\t\t\treturn FALSE;\n", "line_no": 93 }, { "char_end": 2234, "char_start": 2231, "line": "\t}\n", "line_no": 95 }, { "char_end": 2521, "char_start": 2462, "line": "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsColor)\n", "line_no": 108 }, { "char_end": 2537, "char_start": 2521, "line": "\t\treturn FALSE;\n", "line_no": 109 } ], "deleted": [ { "char_end": 1230, "char_start": 1148, "line": "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask + iconInfo->cbBitsColor)\n", "line_no": 44 }, { "char_end": 1246, "char_start": 1230, "line": "\t\treturn FALSE;\n", "line_no": 45 }, { "char_end": 1247, "char_start": 1246, "line": "\n", "line_no": 46 } ] }, "vul_type": "cwe-125" }
482
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static BOOL update_read_icon_info(wStream* s, ICON_INFO* iconInfo)\n{\n\tBYTE* newBitMask;", "\tif (Stream_GetRemainingLength(s) < 8)\n\t\treturn FALSE;", "\tStream_Read_UINT16(s, iconInfo->cacheEntry); /* cacheEntry (2 bytes) */\n\tStream_Read_UINT8(s, iconInfo->cacheId); /* cacheId (1 byte) */\n\tStream_Read_UINT8(s, iconInfo->bpp); /* bpp (1 byte) */", "\tif ((iconInfo->bpp < 1) || (iconInfo->bpp > 32))\n\t{\n\t\tWLog_ERR(TAG, \"invalid bpp value %\" PRIu32 \"\", iconInfo->bpp);\n\t\treturn FALSE;\n\t}", "\tStream_Read_UINT16(s, iconInfo->width); /* width (2 bytes) */\n\tStream_Read_UINT16(s, iconInfo->height); /* height (2 bytes) */", "\t/* cbColorTable is only present when bpp is 1, 4 or 8 */\n\tswitch (iconInfo->bpp)\n\t{\n\t\tcase 1:\n\t\tcase 4:\n\t\tcase 8:\n\t\t\tif (Stream_GetRemainingLength(s) < 2)\n\t\t\t\treturn FALSE;", "\t\t\tStream_Read_UINT16(s, iconInfo->cbColorTable); /* cbColorTable (2 bytes) */\n\t\t\tbreak;", "\t\tdefault:\n\t\t\ticonInfo->cbColorTable = 0;\n\t\t\tbreak;\n\t}", "\tif (Stream_GetRemainingLength(s) < 4)\n\t\treturn FALSE;", "\tStream_Read_UINT16(s, iconInfo->cbBitsMask); /* cbBitsMask (2 bytes) */\n\tStream_Read_UINT16(s, iconInfo->cbBitsColor); /* cbBitsColor (2 bytes) */\n", "", "\t/* bitsMask */\n\tnewBitMask = (BYTE*)realloc(iconInfo->bitsMask, iconInfo->cbBitsMask);", "\tif (!newBitMask)\n\t{\n\t\tfree(iconInfo->bitsMask);\n\t\ticonInfo->bitsMask = NULL;\n\t\treturn FALSE;\n\t}", "\ticonInfo->bitsMask = newBitMask;", "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask)\n\t\treturn FALSE;", "\tStream_Read(s, iconInfo->bitsMask, iconInfo->cbBitsMask);", "\t/* colorTable */\n\tif (iconInfo->colorTable == NULL)\n\t{\n\t\tif (iconInfo->cbColorTable)\n\t\t{\n\t\t\ticonInfo->colorTable = (BYTE*)malloc(iconInfo->cbColorTable);", "\t\t\tif (!iconInfo->colorTable)\n\t\t\t\treturn FALSE;\n\t\t}\n\t}\n\telse if (iconInfo->cbColorTable)\n\t{\n\t\tBYTE* new_tab;\n\t\tnew_tab = (BYTE*)realloc(iconInfo->colorTable, iconInfo->cbColorTable);", "\t\tif (!new_tab)\n\t\t{\n\t\t\tfree(iconInfo->colorTable);\n\t\t\ticonInfo->colorTable = NULL;\n\t\t\treturn FALSE;\n\t\t}", "\t\ticonInfo->colorTable = new_tab;\n\t}\n\telse\n\t{\n\t\tfree(iconInfo->colorTable);\n\t\ticonInfo->colorTable = NULL;\n\t}", "\tif (iconInfo->colorTable)", "\t{\n\t\tif (Stream_GetRemainingLength(s) < iconInfo->cbColorTable)\n\t\t\treturn FALSE;", "\t\tStream_Read(s, iconInfo->colorTable, iconInfo->cbColorTable);", "\t}", "\n\t/* bitsColor */\n\tnewBitMask = (BYTE*)realloc(iconInfo->bitsColor, iconInfo->cbBitsColor);", "\tif (!newBitMask)\n\t{\n\t\tfree(iconInfo->bitsColor);\n\t\ticonInfo->bitsColor = NULL;\n\t\treturn FALSE;\n\t}", "\ticonInfo->bitsColor = newBitMask;", "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsColor)\n\t\treturn FALSE;", "\tStream_Read(s, iconInfo->bitsColor, iconInfo->cbBitsColor);\n\treturn TRUE;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1164, "char_start": 1164, "chars": "" }, { "char_end": 1443, "char_start": 1369, "chars": "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask)\n\t\treturn FALSE;\n" }, { "char_end": 2167, "char_start": 2086, "chars": "\t{\n\t\tif (Stream_GetRemainingLength(s) < iconInfo->cbColorTable)\n\t\t\treturn FALSE;\n" }, { "char_end": 2233, "char_start": 2230, "chars": "\n\t}" }, { "char_end": 2535, "char_start": 2460, "chars": ";\n\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsColor)\n\t\treturn FALSE" } ], "deleted": [ { "char_end": 1248, "char_start": 1149, "chars": "if (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask + iconInfo->cbBitsColor)\n\t\treturn FALSE;\n\n\t" }, { "char_end": 2368, "char_start": 2368, "chars": "" } ] }, "commit_link": "github.com/FreeRDP/FreeRDP/commit/6b2bc41935e53b0034fe5948aeeab4f32e80f30f", "file_name": "libfreerdp/core/window.c", "func_name": "update_read_icon_info", "line_changes": { "added": [ { "char_end": 1427, "char_start": 1369, "line": "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask)\n", "line_no": 55 }, { "char_end": 1443, "char_start": 1427, "line": "\t\treturn FALSE;\n", "line_no": 56 }, { "char_end": 2089, "char_start": 2086, "line": "\t{\n", "line_no": 91 }, { "char_end": 2150, "char_start": 2089, "line": "\t\tif (Stream_GetRemainingLength(s) < iconInfo->cbColorTable)\n", "line_no": 92 }, { "char_end": 2167, "char_start": 2150, "line": "\t\t\treturn FALSE;\n", "line_no": 93 }, { "char_end": 2234, "char_start": 2231, "line": "\t}\n", "line_no": 95 }, { "char_end": 2521, "char_start": 2462, "line": "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsColor)\n", "line_no": 108 }, { "char_end": 2537, "char_start": 2521, "line": "\t\treturn FALSE;\n", "line_no": 109 } ], "deleted": [ { "char_end": 1230, "char_start": 1148, "line": "\tif (Stream_GetRemainingLength(s) < iconInfo->cbBitsMask + iconInfo->cbBitsColor)\n", "line_no": 44 }, { "char_end": 1246, "char_start": 1230, "line": "\t\treturn FALSE;\n", "line_no": 45 }, { "char_end": 1247, "char_start": 1246, "line": "\n", "line_no": 46 } ] }, "vul_type": "cwe-125" }
482
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int usbhid_parse(struct hid_device *hid)\n{\n\tstruct usb_interface *intf = to_usb_interface(hid->dev.parent);\n\tstruct usb_host_interface *interface = intf->cur_altsetting;\n\tstruct usb_device *dev = interface_to_usbdev (intf);\n\tstruct hid_descriptor *hdesc;\n\tu32 quirks = 0;\n\tunsigned int rsize = 0;\n\tchar *rdesc;\n\tint ret, n;", "", "\n\tquirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),\n\t\t\tle16_to_cpu(dev->descriptor.idProduct));", "\tif (quirks & HID_QUIRK_IGNORE)\n\t\treturn -ENODEV;", "\t/* Many keyboards and mice don't like to be polled for reports,\n\t * so we will always set the HID_QUIRK_NOGET flag for them. */\n\tif (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {\n\t\tif (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD ||\n\t\t\tinterface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)\n\t\t\t\tquirks |= HID_QUIRK_NOGET;\n\t}", "\tif (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&\n\t (!interface->desc.bNumEndpoints ||\n\t usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {\n\t\tdbg_hid(\"class descriptor not present\\n\");\n\t\treturn -ENODEV;\n\t}\n", "", "\thid->version = le16_to_cpu(hdesc->bcdHID);\n\thid->country = hdesc->bCountryCode;\n", "\tfor (n = 0; n < hdesc->bNumDescriptors; n++)", "\t\tif (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)\n\t\t\trsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);", "\tif (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {\n\t\tdbg_hid(\"weird size of report descriptor (%u)\\n\", rsize);\n\t\treturn -EINVAL;\n\t}", "\trdesc = kmalloc(rsize, GFP_KERNEL);\n\tif (!rdesc)\n\t\treturn -ENOMEM;", "\thid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);", "\tret = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber,\n\t\t\tHID_DT_REPORT, rdesc, rsize);\n\tif (ret < 0) {\n\t\tdbg_hid(\"reading report descriptor failed\\n\");\n\t\tkfree(rdesc);\n\t\tgoto err;\n\t}", "\tret = hid_parse_report(hid, rdesc, rsize);\n\tkfree(rdesc);\n\tif (ret) {\n\t\tdbg_hid(\"parsing report descriptor failed\\n\");\n\t\tgoto err;\n\t}", "\thid->quirks |= quirks;", "\treturn 0;\nerr:\n\treturn ret;\n}" ]
[ 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 409, "char_start": 331, "chars": "\tint num_descriptors;\n\tsize_t offset = offsetof(struct hid_descriptor, desc);\n" }, { "char_end": 1336, "char_start": 1215, "chars": "if (hdesc->bLength < sizeof(struct hid_descriptor)) {\n\t\tdbg_hid(\"hid descriptor is too short\\n\");\n\t\treturn -EINVAL;\n\t}\n\n\t" }, { "char_end": 1430, "char_start": 1418, "chars": "num_descript" }, { "char_end": 1433, "char_start": 1432, "chars": "s" }, { "char_end": 1441, "char_start": 1434, "chars": "= min_t" }, { "char_end": 1443, "char_start": 1442, "chars": "i" }, { "char_end": 1446, "char_start": 1444, "chars": "t," }, { "char_end": 1472, "char_start": 1447, "chars": "hdesc->bNumDescriptors,\n\t" }, { "char_end": 1476, "char_start": 1473, "chars": " " }, { "char_end": 1480, "char_start": 1479, "chars": "(" }, { "char_end": 1564, "char_start": 1488, "chars": "Length - offset) / sizeof(struct hid_class_descriptor));\n\n\tfor (n = 0; n < n" }, { "char_end": 1568, "char_start": 1566, "chars": "_d" } ], "deleted": [ { "char_end": 1220, "char_start": 1219, "chars": "f" }, { "char_end": 1227, "char_start": 1226, "chars": "=" }, { "char_end": 1230, "char_start": 1228, "chars": "0;" }, { "char_end": 1232, "char_start": 1231, "chars": "n" }, { "char_end": 1234, "char_start": 1233, "chars": "<" }, { "char_end": 1244, "char_start": 1243, "chars": "N" }, { "char_end": 1247, "char_start": 1246, "chars": "D" } ] }, "commit_link": "github.com/torvalds/linux/commit/f043bfc98c193c284e2cd768fefabe18ac2fed9b", "file_name": "drivers/hid/usbhid/hid-core.c", "func_name": "usbhid_parse", "line_changes": { "added": [ { "char_end": 353, "char_start": 331, "line": "\tint num_descriptors;\n", "line_no": 11 }, { "char_end": 409, "char_start": 353, "line": "\tsize_t offset = offsetof(struct hid_descriptor, desc);\n", "line_no": 12 }, { "char_end": 1269, "char_start": 1214, "line": "\tif (hdesc->bLength < sizeof(struct hid_descriptor)) {\n", "line_no": 35 }, { "char_end": 1313, "char_start": 1269, "line": "\t\tdbg_hid(\"hid descriptor is too short\\n\");\n", "line_no": 36 }, { "char_end": 1331, "char_start": 1313, "line": "\t\treturn -EINVAL;\n", "line_no": 37 }, { "char_end": 1334, "char_start": 1331, "line": "\t}\n", "line_no": 38 }, { "char_end": 1335, "char_start": 1334, "line": "\n", "line_no": 39 }, { "char_end": 1471, "char_start": 1417, "line": "\tnum_descriptors = min_t(int, hdesc->bNumDescriptors,\n", "line_no": 43 }, { "char_end": 1545, "char_start": 1471, "line": "\t (hdesc->bLength - offset) / sizeof(struct hid_class_descriptor));\n", "line_no": 44 }, { "char_end": 1546, "char_start": 1545, "line": "\n", "line_no": 45 }, { "char_end": 1585, "char_start": 1546, "line": "\tfor (n = 0; n < num_descriptors; n++)\n", "line_no": 46 } ], "deleted": [ { "char_end": 1264, "char_start": 1218, "line": "\tfor (n = 0; n < hdesc->bNumDescriptors; n++)\n", "line_no": 36 } ] }, "vul_type": "cwe-125" }
483
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int usbhid_parse(struct hid_device *hid)\n{\n\tstruct usb_interface *intf = to_usb_interface(hid->dev.parent);\n\tstruct usb_host_interface *interface = intf->cur_altsetting;\n\tstruct usb_device *dev = interface_to_usbdev (intf);\n\tstruct hid_descriptor *hdesc;\n\tu32 quirks = 0;\n\tunsigned int rsize = 0;\n\tchar *rdesc;\n\tint ret, n;", "\tint num_descriptors;\n\tsize_t offset = offsetof(struct hid_descriptor, desc);", "\n\tquirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),\n\t\t\tle16_to_cpu(dev->descriptor.idProduct));", "\tif (quirks & HID_QUIRK_IGNORE)\n\t\treturn -ENODEV;", "\t/* Many keyboards and mice don't like to be polled for reports,\n\t * so we will always set the HID_QUIRK_NOGET flag for them. */\n\tif (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {\n\t\tif (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD ||\n\t\t\tinterface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)\n\t\t\t\tquirks |= HID_QUIRK_NOGET;\n\t}", "\tif (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&\n\t (!interface->desc.bNumEndpoints ||\n\t usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {\n\t\tdbg_hid(\"class descriptor not present\\n\");\n\t\treturn -ENODEV;\n\t}\n", "\tif (hdesc->bLength < sizeof(struct hid_descriptor)) {\n\t\tdbg_hid(\"hid descriptor is too short\\n\");\n\t\treturn -EINVAL;\n\t}\n", "\thid->version = le16_to_cpu(hdesc->bcdHID);\n\thid->country = hdesc->bCountryCode;\n", "\tnum_descriptors = min_t(int, hdesc->bNumDescriptors,\n\t (hdesc->bLength - offset) / sizeof(struct hid_class_descriptor));", "\tfor (n = 0; n < num_descriptors; n++)", "\t\tif (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)\n\t\t\trsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);", "\tif (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {\n\t\tdbg_hid(\"weird size of report descriptor (%u)\\n\", rsize);\n\t\treturn -EINVAL;\n\t}", "\trdesc = kmalloc(rsize, GFP_KERNEL);\n\tif (!rdesc)\n\t\treturn -ENOMEM;", "\thid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);", "\tret = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber,\n\t\t\tHID_DT_REPORT, rdesc, rsize);\n\tif (ret < 0) {\n\t\tdbg_hid(\"reading report descriptor failed\\n\");\n\t\tkfree(rdesc);\n\t\tgoto err;\n\t}", "\tret = hid_parse_report(hid, rdesc, rsize);\n\tkfree(rdesc);\n\tif (ret) {\n\t\tdbg_hid(\"parsing report descriptor failed\\n\");\n\t\tgoto err;\n\t}", "\thid->quirks |= quirks;", "\treturn 0;\nerr:\n\treturn ret;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 409, "char_start": 331, "chars": "\tint num_descriptors;\n\tsize_t offset = offsetof(struct hid_descriptor, desc);\n" }, { "char_end": 1336, "char_start": 1215, "chars": "if (hdesc->bLength < sizeof(struct hid_descriptor)) {\n\t\tdbg_hid(\"hid descriptor is too short\\n\");\n\t\treturn -EINVAL;\n\t}\n\n\t" }, { "char_end": 1430, "char_start": 1418, "chars": "num_descript" }, { "char_end": 1433, "char_start": 1432, "chars": "s" }, { "char_end": 1441, "char_start": 1434, "chars": "= min_t" }, { "char_end": 1443, "char_start": 1442, "chars": "i" }, { "char_end": 1446, "char_start": 1444, "chars": "t," }, { "char_end": 1472, "char_start": 1447, "chars": "hdesc->bNumDescriptors,\n\t" }, { "char_end": 1476, "char_start": 1473, "chars": " " }, { "char_end": 1480, "char_start": 1479, "chars": "(" }, { "char_end": 1564, "char_start": 1488, "chars": "Length - offset) / sizeof(struct hid_class_descriptor));\n\n\tfor (n = 0; n < n" }, { "char_end": 1568, "char_start": 1566, "chars": "_d" } ], "deleted": [ { "char_end": 1220, "char_start": 1219, "chars": "f" }, { "char_end": 1227, "char_start": 1226, "chars": "=" }, { "char_end": 1230, "char_start": 1228, "chars": "0;" }, { "char_end": 1232, "char_start": 1231, "chars": "n" }, { "char_end": 1234, "char_start": 1233, "chars": "<" }, { "char_end": 1244, "char_start": 1243, "chars": "N" }, { "char_end": 1247, "char_start": 1246, "chars": "D" } ] }, "commit_link": "github.com/torvalds/linux/commit/f043bfc98c193c284e2cd768fefabe18ac2fed9b", "file_name": "drivers/hid/usbhid/hid-core.c", "func_name": "usbhid_parse", "line_changes": { "added": [ { "char_end": 353, "char_start": 331, "line": "\tint num_descriptors;\n", "line_no": 11 }, { "char_end": 409, "char_start": 353, "line": "\tsize_t offset = offsetof(struct hid_descriptor, desc);\n", "line_no": 12 }, { "char_end": 1269, "char_start": 1214, "line": "\tif (hdesc->bLength < sizeof(struct hid_descriptor)) {\n", "line_no": 35 }, { "char_end": 1313, "char_start": 1269, "line": "\t\tdbg_hid(\"hid descriptor is too short\\n\");\n", "line_no": 36 }, { "char_end": 1331, "char_start": 1313, "line": "\t\treturn -EINVAL;\n", "line_no": 37 }, { "char_end": 1334, "char_start": 1331, "line": "\t}\n", "line_no": 38 }, { "char_end": 1335, "char_start": 1334, "line": "\n", "line_no": 39 }, { "char_end": 1471, "char_start": 1417, "line": "\tnum_descriptors = min_t(int, hdesc->bNumDescriptors,\n", "line_no": 43 }, { "char_end": 1545, "char_start": 1471, "line": "\t (hdesc->bLength - offset) / sizeof(struct hid_class_descriptor));\n", "line_no": 44 }, { "char_end": 1546, "char_start": 1545, "line": "\n", "line_no": 45 }, { "char_end": 1585, "char_start": 1546, "line": "\tfor (n = 0; n < num_descriptors; n++)\n", "line_no": 46 } ], "deleted": [ { "char_end": 1264, "char_start": 1218, "line": "\tfor (n = 0; n < hdesc->bNumDescriptors; n++)\n", "line_no": 36 } ] }, "vul_type": "cwe-125" }
483
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void exif_process_APP12(image_info_type *ImageInfo,\n char *buffer, size_t length) {\n size_t l1, l2=0;\n if ((l1 = php_strnlen(buffer+2, length-2)) > 0) {\n exif_iif_add_tag(ImageInfo, SECTION_APP12, \"Company\",\n TAG_NONE, TAG_FMT_STRING, l1, buffer+2);\n if (length > 2+l1+1) {", " l2 = php_strnlen(buffer+2+l1+1, length-2-l1+1);", " exif_iif_add_tag(ImageInfo, SECTION_APP12, \"Info\",\n TAG_NONE, TAG_FMT_STRING, l2, buffer+2+l1+1);\n }\n }\n}" ]
[ 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 389, "char_start": 388, "chars": "-" } ], "deleted": [ { "char_end": 389, "char_start": 388, "chars": "+" } ] }, "commit_link": "github.com/facebook/hhvm/commit/f1cd34e63c2a0d9702be3d41462db7bfd0ae7da3", "file_name": "hphp/runtime/ext/gd/ext_gd.cpp", "func_name": "HPHP::exif_process_APP12", "line_changes": { "added": [ { "char_end": 393, "char_start": 339, "line": " l2 = php_strnlen(buffer+2+l1+1, length-2-l1-1);\n", "line_no": 8 } ], "deleted": [ { "char_end": 393, "char_start": 339, "line": " l2 = php_strnlen(buffer+2+l1+1, length-2-l1+1);\n", "line_no": 8 } ] }, "vul_type": "cwe-125" }
484
cwe-125
cpp
Determine whether the {function_name} code is vulnerable or not.
[ "static void exif_process_APP12(image_info_type *ImageInfo,\n char *buffer, size_t length) {\n size_t l1, l2=0;\n if ((l1 = php_strnlen(buffer+2, length-2)) > 0) {\n exif_iif_add_tag(ImageInfo, SECTION_APP12, \"Company\",\n TAG_NONE, TAG_FMT_STRING, l1, buffer+2);\n if (length > 2+l1+1) {", " l2 = php_strnlen(buffer+2+l1+1, length-2-l1-1);", " exif_iif_add_tag(ImageInfo, SECTION_APP12, \"Info\",\n TAG_NONE, TAG_FMT_STRING, l2, buffer+2+l1+1);\n }\n }\n}" ]
[ 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 389, "char_start": 388, "chars": "-" } ], "deleted": [ { "char_end": 389, "char_start": 388, "chars": "+" } ] }, "commit_link": "github.com/facebook/hhvm/commit/f1cd34e63c2a0d9702be3d41462db7bfd0ae7da3", "file_name": "hphp/runtime/ext/gd/ext_gd.cpp", "func_name": "HPHP::exif_process_APP12", "line_changes": { "added": [ { "char_end": 393, "char_start": 339, "line": " l2 = php_strnlen(buffer+2+l1+1, length-2-l1-1);\n", "line_no": 8 } ], "deleted": [ { "char_end": 393, "char_start": 339, "line": " l2 = php_strnlen(buffer+2+l1+1, length-2-l1+1);\n", "line_no": 8 } ] }, "vul_type": "cwe-125" }
484
cwe-125
cpp
Determine whether the {function_name} code is vulnerable or not.
[ "int modbus_reply(modbus_t *ctx, const uint8_t *req,\n int req_length, modbus_mapping_t *mb_mapping)\n{\n int offset;\n int slave;\n int function;\n uint16_t address;\n uint8_t rsp[MAX_MESSAGE_LENGTH];\n int rsp_length = 0;\n sft_t sft;", " if (ctx == NULL) {\n errno = EINVAL;\n return -1;\n }", " offset = ctx->backend->header_length;\n slave = req[offset - 1];\n function = req[offset];\n address = (req[offset + 1] << 8) + req[offset + 2];", " sft.slave = slave;\n sft.function = function;\n sft.t_id = ctx->backend->prepare_response_tid(req, &req_length);", " /* Data are flushed on illegal number of values errors. */\n switch (function) {\n case MODBUS_FC_READ_COILS:\n case MODBUS_FC_READ_DISCRETE_INPUTS: {\n unsigned int is_input = (function == MODBUS_FC_READ_DISCRETE_INPUTS);\n int start_bits = is_input ? mb_mapping->start_input_bits : mb_mapping->start_bits;\n int nb_bits = is_input ? mb_mapping->nb_input_bits : mb_mapping->nb_bits;\n uint8_t *tab_bits = is_input ? mb_mapping->tab_input_bits : mb_mapping->tab_bits;\n const char * const name = is_input ? \"read_input_bits\" : \"read_bits\";\n int nb = (req[offset + 3] << 8) + req[offset + 4];\n /* The mapping can be shifted to reduce memory consumption and it\n doesn't always start at address zero. */\n int mapping_address = address - start_bits;", " if (nb < 1 || MODBUS_MAX_READ_BITS < nb) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal nb of values %d in %s (max %d)\\n\",\n nb, name, MODBUS_MAX_READ_BITS);\n } else if (mapping_address < 0 || (mapping_address + nb) > nb_bits) {\n rsp_length = response_exception(\n ctx, &sft,\n MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in %s\\n\",\n mapping_address < 0 ? address : address + nb, name);\n } else {\n rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n rsp[rsp_length++] = (nb / 8) + ((nb % 8) ? 1 : 0);\n rsp_length = response_io_status(tab_bits, mapping_address, nb,\n rsp, rsp_length);\n }\n }\n break;\n case MODBUS_FC_READ_HOLDING_REGISTERS:\n case MODBUS_FC_READ_INPUT_REGISTERS: {\n unsigned int is_input = (function == MODBUS_FC_READ_INPUT_REGISTERS);\n int start_registers = is_input ? mb_mapping->start_input_registers : mb_mapping->start_registers;\n int nb_registers = is_input ? mb_mapping->nb_input_registers : mb_mapping->nb_registers;\n uint16_t *tab_registers = is_input ? mb_mapping->tab_input_registers : mb_mapping->tab_registers;\n const char * const name = is_input ? \"read_input_registers\" : \"read_registers\";\n int nb = (req[offset + 3] << 8) + req[offset + 4];\n /* The mapping can be shifted to reduce memory consumption and it\n doesn't always start at address zero. */\n int mapping_address = address - start_registers;", " if (nb < 1 || MODBUS_MAX_READ_REGISTERS < nb) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal nb of values %d in %s (max %d)\\n\",\n nb, name, MODBUS_MAX_READ_REGISTERS);\n } else if (mapping_address < 0 || (mapping_address + nb) > nb_registers) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in %s\\n\",\n mapping_address < 0 ? address : address + nb, name);\n } else {\n int i;", " rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n rsp[rsp_length++] = nb << 1;\n for (i = mapping_address; i < mapping_address + nb; i++) {\n rsp[rsp_length++] = tab_registers[i] >> 8;\n rsp[rsp_length++] = tab_registers[i] & 0xFF;\n }\n }\n }\n break;\n case MODBUS_FC_WRITE_SINGLE_COIL: {\n int mapping_address = address - mb_mapping->start_bits;", " if (mapping_address < 0 || mapping_address >= mb_mapping->nb_bits) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_bit\\n\",\n address);\n } else {\n int data = (req[offset + 3] << 8) + req[offset + 4];", " if (data == 0xFF00 || data == 0x0) {\n mb_mapping->tab_bits[mapping_address] = data ? ON : OFF;\n memcpy(rsp, req, req_length);\n rsp_length = req_length;\n } else {\n rsp_length = response_exception(\n ctx, &sft,\n MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, FALSE,\n \"Illegal data value 0x%0X in write_bit request at address %0X\\n\",\n data, address);\n }\n }\n }\n break;\n case MODBUS_FC_WRITE_SINGLE_REGISTER: {\n int mapping_address = address - mb_mapping->start_registers;", " if (mapping_address < 0 || mapping_address >= mb_mapping->nb_registers) {\n rsp_length = response_exception(\n ctx, &sft,\n MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_register\\n\",\n address);\n } else {\n int data = (req[offset + 3] << 8) + req[offset + 4];", " mb_mapping->tab_registers[mapping_address] = data;\n memcpy(rsp, req, req_length);\n rsp_length = req_length;\n }\n }\n break;\n case MODBUS_FC_WRITE_MULTIPLE_COILS: {\n int nb = (req[offset + 3] << 8) + req[offset + 4];", "", " int mapping_address = address - mb_mapping->start_bits;\n", " if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb) {", " /* May be the indication has been truncated on reading because of\n * invalid address (eg. nb is 0 but the request contains values to\n * write) so it's necessary to flush. */\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal number of values %d in write_bits (max %d)\\n\",\n nb, MODBUS_MAX_WRITE_BITS);\n } else if (mapping_address < 0 ||\n (mapping_address + nb) > mb_mapping->nb_bits) {\n rsp_length = response_exception(\n ctx, &sft,\n MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_bits\\n\",\n mapping_address < 0 ? address : address + nb);\n } else {\n /* 6 = byte count */\n modbus_set_bits_from_bytes(mb_mapping->tab_bits, mapping_address, nb,\n &req[offset + 6]);", " rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n /* 4 to copy the bit address (2) and the quantity of bits */\n memcpy(rsp + rsp_length, req + rsp_length, 4);\n rsp_length += 4;\n }\n }\n break;\n case MODBUS_FC_WRITE_MULTIPLE_REGISTERS: {\n int nb = (req[offset + 3] << 8) + req[offset + 4];", " int mapping_address = address - mb_mapping->start_registers;", " if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb) {", " rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal number of values %d in write_registers (max %d)\\n\",\n nb, MODBUS_MAX_WRITE_REGISTERS);\n } else if (mapping_address < 0 ||\n (mapping_address + nb) > mb_mapping->nb_registers) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_registers\\n\",\n mapping_address < 0 ? address : address + nb);\n } else {\n int i, j;\n for (i = mapping_address, j = 6; i < mapping_address + nb; i++, j += 2) {\n /* 6 and 7 = first value */\n mb_mapping->tab_registers[i] =\n (req[offset + j] << 8) + req[offset + j + 1];\n }", " rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n /* 4 to copy the address (2) and the no. of registers */\n memcpy(rsp + rsp_length, req + rsp_length, 4);\n rsp_length += 4;\n }\n }\n break;\n case MODBUS_FC_REPORT_SLAVE_ID: {\n int str_len;\n int byte_count_pos;", " rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n /* Skip byte count for now */\n byte_count_pos = rsp_length++;\n rsp[rsp_length++] = _REPORT_SLAVE_ID;\n /* Run indicator status to ON */\n rsp[rsp_length++] = 0xFF;\n /* LMB + length of LIBMODBUS_VERSION_STRING */\n str_len = 3 + strlen(LIBMODBUS_VERSION_STRING);\n memcpy(rsp + rsp_length, \"LMB\" LIBMODBUS_VERSION_STRING, str_len);\n rsp_length += str_len;\n rsp[byte_count_pos] = rsp_length - byte_count_pos - 1;\n }\n break;\n case MODBUS_FC_READ_EXCEPTION_STATUS:\n if (ctx->debug) {\n fprintf(stderr, \"FIXME Not implemented\\n\");\n }\n errno = ENOPROTOOPT;\n return -1;\n break;\n case MODBUS_FC_MASK_WRITE_REGISTER: {\n int mapping_address = address - mb_mapping->start_registers;", " if (mapping_address < 0 || mapping_address >= mb_mapping->nb_registers) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_register\\n\",\n address);\n } else {\n uint16_t data = mb_mapping->tab_registers[mapping_address];\n uint16_t and = (req[offset + 3] << 8) + req[offset + 4];\n uint16_t or = (req[offset + 5] << 8) + req[offset + 6];", " data = (data & and) | (or & (~and));\n mb_mapping->tab_registers[mapping_address] = data;\n memcpy(rsp, req, req_length);\n rsp_length = req_length;\n }\n }\n break;\n case MODBUS_FC_WRITE_AND_READ_REGISTERS: {\n int nb = (req[offset + 3] << 8) + req[offset + 4];\n uint16_t address_write = (req[offset + 5] << 8) + req[offset + 6];\n int nb_write = (req[offset + 7] << 8) + req[offset + 8];\n int nb_write_bytes = req[offset + 9];\n int mapping_address = address - mb_mapping->start_registers;\n int mapping_address_write = address_write - mb_mapping->start_registers;", " if (nb_write < 1 || MODBUS_MAX_WR_WRITE_REGISTERS < nb_write ||\n nb < 1 || MODBUS_MAX_WR_READ_REGISTERS < nb ||\n nb_write_bytes != nb_write * 2) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal nb of values (W%d, R%d) in write_and_read_registers (max W%d, R%d)\\n\",\n nb_write, nb, MODBUS_MAX_WR_WRITE_REGISTERS, MODBUS_MAX_WR_READ_REGISTERS);\n } else if (mapping_address < 0 ||\n (mapping_address + nb) > mb_mapping->nb_registers ||\n mapping_address < 0 ||\n (mapping_address_write + nb_write) > mb_mapping->nb_registers) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data read address 0x%0X or write address 0x%0X write_and_read_registers\\n\",\n mapping_address < 0 ? address : address + nb,\n mapping_address_write < 0 ? address_write : address_write + nb_write);\n } else {\n int i, j;\n rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n rsp[rsp_length++] = nb << 1;", " /* Write first.\n 10 and 11 are the offset of the first values to write */\n for (i = mapping_address_write, j = 10;\n i < mapping_address_write + nb_write; i++, j += 2) {\n mb_mapping->tab_registers[i] =\n (req[offset + j] << 8) + req[offset + j + 1];\n }", " /* and read the data for the response */\n for (i = mapping_address; i < mapping_address + nb; i++) {\n rsp[rsp_length++] = mb_mapping->tab_registers[i] >> 8;\n rsp[rsp_length++] = mb_mapping->tab_registers[i] & 0xFF;\n }\n }\n }\n break;", " default:\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_FUNCTION, rsp, TRUE,\n \"Unknown Modbus function code: 0x%0X\\n\", function);\n break;\n }", " /* Suppress any responses when the request was a broadcast */\n return (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU &&\n slave == MODBUS_BROADCAST_ADDRESS) ? 0 : send_msg(ctx, rsp, rsp_length);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 6040, "char_start": 6001, "chars": "nb_bits = req[offset + 5];\n int " }, { "char_end": 6156, "char_start": 6136, "chars": " < nb || nb_bits * 8" }, { "char_end": 7597, "char_start": 7557, "chars": "nb_bytes = req[offset + 5];\n int " }, { "char_end": 7724, "char_start": 7703, "chars": " < nb || nb_bytes * 8" } ], "deleted": [] }, "commit_link": "github.com/stephane/libmodbus/commit/5ccdf5ef79d742640355d1132fa9e2abc7fbaefc", "file_name": "src/modbus.c", "func_name": "modbus_reply", "line_changes": { "added": [ { "char_end": 6028, "char_start": 5989, "line": " int nb_bits = req[offset + 5];\n", "line_no": 138 }, { "char_end": 6165, "char_start": 6093, "line": " if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb || nb_bits * 8 < nb) {\n", "line_no": 141 }, { "char_end": 7585, "char_start": 7545, "line": " int nb_bytes = req[offset + 5];\n", "line_no": 170 }, { "char_end": 7733, "char_start": 7655, "line": " if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb || nb_bytes * 8 < nb) {\n", "line_no": 173 } ], "deleted": [ { "char_end": 6106, "char_start": 6054, "line": " if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb) {\n", "line_no": 140 }, { "char_end": 7613, "char_start": 7556, "line": " if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb) {\n", "line_no": 171 } ] }, "vul_type": "cwe-125" }
485
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "int modbus_reply(modbus_t *ctx, const uint8_t *req,\n int req_length, modbus_mapping_t *mb_mapping)\n{\n int offset;\n int slave;\n int function;\n uint16_t address;\n uint8_t rsp[MAX_MESSAGE_LENGTH];\n int rsp_length = 0;\n sft_t sft;", " if (ctx == NULL) {\n errno = EINVAL;\n return -1;\n }", " offset = ctx->backend->header_length;\n slave = req[offset - 1];\n function = req[offset];\n address = (req[offset + 1] << 8) + req[offset + 2];", " sft.slave = slave;\n sft.function = function;\n sft.t_id = ctx->backend->prepare_response_tid(req, &req_length);", " /* Data are flushed on illegal number of values errors. */\n switch (function) {\n case MODBUS_FC_READ_COILS:\n case MODBUS_FC_READ_DISCRETE_INPUTS: {\n unsigned int is_input = (function == MODBUS_FC_READ_DISCRETE_INPUTS);\n int start_bits = is_input ? mb_mapping->start_input_bits : mb_mapping->start_bits;\n int nb_bits = is_input ? mb_mapping->nb_input_bits : mb_mapping->nb_bits;\n uint8_t *tab_bits = is_input ? mb_mapping->tab_input_bits : mb_mapping->tab_bits;\n const char * const name = is_input ? \"read_input_bits\" : \"read_bits\";\n int nb = (req[offset + 3] << 8) + req[offset + 4];\n /* The mapping can be shifted to reduce memory consumption and it\n doesn't always start at address zero. */\n int mapping_address = address - start_bits;", " if (nb < 1 || MODBUS_MAX_READ_BITS < nb) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal nb of values %d in %s (max %d)\\n\",\n nb, name, MODBUS_MAX_READ_BITS);\n } else if (mapping_address < 0 || (mapping_address + nb) > nb_bits) {\n rsp_length = response_exception(\n ctx, &sft,\n MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in %s\\n\",\n mapping_address < 0 ? address : address + nb, name);\n } else {\n rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n rsp[rsp_length++] = (nb / 8) + ((nb % 8) ? 1 : 0);\n rsp_length = response_io_status(tab_bits, mapping_address, nb,\n rsp, rsp_length);\n }\n }\n break;\n case MODBUS_FC_READ_HOLDING_REGISTERS:\n case MODBUS_FC_READ_INPUT_REGISTERS: {\n unsigned int is_input = (function == MODBUS_FC_READ_INPUT_REGISTERS);\n int start_registers = is_input ? mb_mapping->start_input_registers : mb_mapping->start_registers;\n int nb_registers = is_input ? mb_mapping->nb_input_registers : mb_mapping->nb_registers;\n uint16_t *tab_registers = is_input ? mb_mapping->tab_input_registers : mb_mapping->tab_registers;\n const char * const name = is_input ? \"read_input_registers\" : \"read_registers\";\n int nb = (req[offset + 3] << 8) + req[offset + 4];\n /* The mapping can be shifted to reduce memory consumption and it\n doesn't always start at address zero. */\n int mapping_address = address - start_registers;", " if (nb < 1 || MODBUS_MAX_READ_REGISTERS < nb) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal nb of values %d in %s (max %d)\\n\",\n nb, name, MODBUS_MAX_READ_REGISTERS);\n } else if (mapping_address < 0 || (mapping_address + nb) > nb_registers) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in %s\\n\",\n mapping_address < 0 ? address : address + nb, name);\n } else {\n int i;", " rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n rsp[rsp_length++] = nb << 1;\n for (i = mapping_address; i < mapping_address + nb; i++) {\n rsp[rsp_length++] = tab_registers[i] >> 8;\n rsp[rsp_length++] = tab_registers[i] & 0xFF;\n }\n }\n }\n break;\n case MODBUS_FC_WRITE_SINGLE_COIL: {\n int mapping_address = address - mb_mapping->start_bits;", " if (mapping_address < 0 || mapping_address >= mb_mapping->nb_bits) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_bit\\n\",\n address);\n } else {\n int data = (req[offset + 3] << 8) + req[offset + 4];", " if (data == 0xFF00 || data == 0x0) {\n mb_mapping->tab_bits[mapping_address] = data ? ON : OFF;\n memcpy(rsp, req, req_length);\n rsp_length = req_length;\n } else {\n rsp_length = response_exception(\n ctx, &sft,\n MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, FALSE,\n \"Illegal data value 0x%0X in write_bit request at address %0X\\n\",\n data, address);\n }\n }\n }\n break;\n case MODBUS_FC_WRITE_SINGLE_REGISTER: {\n int mapping_address = address - mb_mapping->start_registers;", " if (mapping_address < 0 || mapping_address >= mb_mapping->nb_registers) {\n rsp_length = response_exception(\n ctx, &sft,\n MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_register\\n\",\n address);\n } else {\n int data = (req[offset + 3] << 8) + req[offset + 4];", " mb_mapping->tab_registers[mapping_address] = data;\n memcpy(rsp, req, req_length);\n rsp_length = req_length;\n }\n }\n break;\n case MODBUS_FC_WRITE_MULTIPLE_COILS: {\n int nb = (req[offset + 3] << 8) + req[offset + 4];", " int nb_bits = req[offset + 5];", " int mapping_address = address - mb_mapping->start_bits;\n", " if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb || nb_bits * 8 < nb) {", " /* May be the indication has been truncated on reading because of\n * invalid address (eg. nb is 0 but the request contains values to\n * write) so it's necessary to flush. */\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal number of values %d in write_bits (max %d)\\n\",\n nb, MODBUS_MAX_WRITE_BITS);\n } else if (mapping_address < 0 ||\n (mapping_address + nb) > mb_mapping->nb_bits) {\n rsp_length = response_exception(\n ctx, &sft,\n MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_bits\\n\",\n mapping_address < 0 ? address : address + nb);\n } else {\n /* 6 = byte count */\n modbus_set_bits_from_bytes(mb_mapping->tab_bits, mapping_address, nb,\n &req[offset + 6]);", " rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n /* 4 to copy the bit address (2) and the quantity of bits */\n memcpy(rsp + rsp_length, req + rsp_length, 4);\n rsp_length += 4;\n }\n }\n break;\n case MODBUS_FC_WRITE_MULTIPLE_REGISTERS: {\n int nb = (req[offset + 3] << 8) + req[offset + 4];", " int nb_bytes = req[offset + 5];\n int mapping_address = address - mb_mapping->start_registers;", " if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb || nb_bytes * 8 < nb) {", " rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal number of values %d in write_registers (max %d)\\n\",\n nb, MODBUS_MAX_WRITE_REGISTERS);\n } else if (mapping_address < 0 ||\n (mapping_address + nb) > mb_mapping->nb_registers) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_registers\\n\",\n mapping_address < 0 ? address : address + nb);\n } else {\n int i, j;\n for (i = mapping_address, j = 6; i < mapping_address + nb; i++, j += 2) {\n /* 6 and 7 = first value */\n mb_mapping->tab_registers[i] =\n (req[offset + j] << 8) + req[offset + j + 1];\n }", " rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n /* 4 to copy the address (2) and the no. of registers */\n memcpy(rsp + rsp_length, req + rsp_length, 4);\n rsp_length += 4;\n }\n }\n break;\n case MODBUS_FC_REPORT_SLAVE_ID: {\n int str_len;\n int byte_count_pos;", " rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n /* Skip byte count for now */\n byte_count_pos = rsp_length++;\n rsp[rsp_length++] = _REPORT_SLAVE_ID;\n /* Run indicator status to ON */\n rsp[rsp_length++] = 0xFF;\n /* LMB + length of LIBMODBUS_VERSION_STRING */\n str_len = 3 + strlen(LIBMODBUS_VERSION_STRING);\n memcpy(rsp + rsp_length, \"LMB\" LIBMODBUS_VERSION_STRING, str_len);\n rsp_length += str_len;\n rsp[byte_count_pos] = rsp_length - byte_count_pos - 1;\n }\n break;\n case MODBUS_FC_READ_EXCEPTION_STATUS:\n if (ctx->debug) {\n fprintf(stderr, \"FIXME Not implemented\\n\");\n }\n errno = ENOPROTOOPT;\n return -1;\n break;\n case MODBUS_FC_MASK_WRITE_REGISTER: {\n int mapping_address = address - mb_mapping->start_registers;", " if (mapping_address < 0 || mapping_address >= mb_mapping->nb_registers) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data address 0x%0X in write_register\\n\",\n address);\n } else {\n uint16_t data = mb_mapping->tab_registers[mapping_address];\n uint16_t and = (req[offset + 3] << 8) + req[offset + 4];\n uint16_t or = (req[offset + 5] << 8) + req[offset + 6];", " data = (data & and) | (or & (~and));\n mb_mapping->tab_registers[mapping_address] = data;\n memcpy(rsp, req, req_length);\n rsp_length = req_length;\n }\n }\n break;\n case MODBUS_FC_WRITE_AND_READ_REGISTERS: {\n int nb = (req[offset + 3] << 8) + req[offset + 4];\n uint16_t address_write = (req[offset + 5] << 8) + req[offset + 6];\n int nb_write = (req[offset + 7] << 8) + req[offset + 8];\n int nb_write_bytes = req[offset + 9];\n int mapping_address = address - mb_mapping->start_registers;\n int mapping_address_write = address_write - mb_mapping->start_registers;", " if (nb_write < 1 || MODBUS_MAX_WR_WRITE_REGISTERS < nb_write ||\n nb < 1 || MODBUS_MAX_WR_READ_REGISTERS < nb ||\n nb_write_bytes != nb_write * 2) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,\n \"Illegal nb of values (W%d, R%d) in write_and_read_registers (max W%d, R%d)\\n\",\n nb_write, nb, MODBUS_MAX_WR_WRITE_REGISTERS, MODBUS_MAX_WR_READ_REGISTERS);\n } else if (mapping_address < 0 ||\n (mapping_address + nb) > mb_mapping->nb_registers ||\n mapping_address < 0 ||\n (mapping_address_write + nb_write) > mb_mapping->nb_registers) {\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,\n \"Illegal data read address 0x%0X or write address 0x%0X write_and_read_registers\\n\",\n mapping_address < 0 ? address : address + nb,\n mapping_address_write < 0 ? address_write : address_write + nb_write);\n } else {\n int i, j;\n rsp_length = ctx->backend->build_response_basis(&sft, rsp);\n rsp[rsp_length++] = nb << 1;", " /* Write first.\n 10 and 11 are the offset of the first values to write */\n for (i = mapping_address_write, j = 10;\n i < mapping_address_write + nb_write; i++, j += 2) {\n mb_mapping->tab_registers[i] =\n (req[offset + j] << 8) + req[offset + j + 1];\n }", " /* and read the data for the response */\n for (i = mapping_address; i < mapping_address + nb; i++) {\n rsp[rsp_length++] = mb_mapping->tab_registers[i] >> 8;\n rsp[rsp_length++] = mb_mapping->tab_registers[i] & 0xFF;\n }\n }\n }\n break;", " default:\n rsp_length = response_exception(\n ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_FUNCTION, rsp, TRUE,\n \"Unknown Modbus function code: 0x%0X\\n\", function);\n break;\n }", " /* Suppress any responses when the request was a broadcast */\n return (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_RTU &&\n slave == MODBUS_BROADCAST_ADDRESS) ? 0 : send_msg(ctx, rsp, rsp_length);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 6040, "char_start": 6001, "chars": "nb_bits = req[offset + 5];\n int " }, { "char_end": 6156, "char_start": 6136, "chars": " < nb || nb_bits * 8" }, { "char_end": 7597, "char_start": 7557, "chars": "nb_bytes = req[offset + 5];\n int " }, { "char_end": 7724, "char_start": 7703, "chars": " < nb || nb_bytes * 8" } ], "deleted": [] }, "commit_link": "github.com/stephane/libmodbus/commit/5ccdf5ef79d742640355d1132fa9e2abc7fbaefc", "file_name": "src/modbus.c", "func_name": "modbus_reply", "line_changes": { "added": [ { "char_end": 6028, "char_start": 5989, "line": " int nb_bits = req[offset + 5];\n", "line_no": 138 }, { "char_end": 6165, "char_start": 6093, "line": " if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb || nb_bits * 8 < nb) {\n", "line_no": 141 }, { "char_end": 7585, "char_start": 7545, "line": " int nb_bytes = req[offset + 5];\n", "line_no": 170 }, { "char_end": 7733, "char_start": 7655, "line": " if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb || nb_bytes * 8 < nb) {\n", "line_no": 173 } ], "deleted": [ { "char_end": 6106, "char_start": 6054, "line": " if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb) {\n", "line_no": 140 }, { "char_end": 7613, "char_start": 7556, "line": " if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb) {\n", "line_no": 171 } ] }, "vul_type": "cwe-125" }
485
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static Sdb *store_versioninfo_gnu_verneed(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) {\n\tut8 *end, *need = NULL;\n\tconst char *section_name = \"\";\n\tElf_(Shdr) *link_shdr = NULL;\n\tconst char *link_section_name = \"\";\n\tSdb *sdb_vernaux = NULL;\n\tSdb *sdb_version = NULL;\n\tSdb *sdb = NULL;\n\tint i, cnt;", "\tif (!bin || !bin->dynstr) {\n\t\treturn NULL;\n\t}\n\tif (shdr->sh_link > bin->ehdr.e_shnum) {\n\t\treturn NULL;\n\t}\n\tif (shdr->sh_size < 1) {\n\t\treturn NULL;\n\t}\n\tsdb = sdb_new0 ();\n\tif (!sdb) {\n\t\treturn NULL;\n\t}\n\tlink_shdr = &bin->shdr[shdr->sh_link];\n\tif (bin->shstrtab && shdr->sh_name < bin->shstrtab_size) {\n\t\tsection_name = &bin->shstrtab[shdr->sh_name];\n\t}\n\tif (bin->shstrtab && link_shdr->sh_name < bin->shstrtab_size) {\n\t\tlink_section_name = &bin->shstrtab[link_shdr->sh_name];\n\t}\n\tif (!(need = (ut8*) calloc (R_MAX (1, shdr->sh_size), sizeof (ut8)))) {\n\t\tbprintf (\"Warning: Cannot allocate memory for Elf_(Verneed)\\n\");\n\t\tgoto beach;\n\t}\n\tend = need + shdr->sh_size;\n\tsdb_set (sdb, \"section_name\", section_name, 0);\n\tsdb_num_set (sdb, \"num_entries\", shdr->sh_info, 0);\n\tsdb_num_set (sdb, \"addr\", shdr->sh_addr, 0);\n\tsdb_num_set (sdb, \"offset\", shdr->sh_offset, 0);\n\tsdb_num_set (sdb, \"link\", shdr->sh_link, 0);\n\tsdb_set (sdb, \"link_section_name\", link_section_name, 0);", "\tif (shdr->sh_offset > bin->size || shdr->sh_offset + shdr->sh_size > bin->size) {\n\t\tgoto beach;\n\t}\n\tif (shdr->sh_offset + shdr->sh_size < shdr->sh_size) {\n\t\tgoto beach;\n\t}\n\ti = r_buf_read_at (bin->b, shdr->sh_offset, need, shdr->sh_size);\n\tif (i < 0)\n\t\tgoto beach;\n\t//XXX we should use DT_VERNEEDNUM instead of sh_info\n\t//TODO https://sourceware.org/ml/binutils/2014-11/msg00353.html\n\tfor (i = 0, cnt = 0; cnt < shdr->sh_info; ++cnt) {\n\t\tint j, isum;\n\t\tut8 *vstart = need + i;\n\t\tElf_(Verneed) vvn = {0};\n\t\tif (vstart + sizeof (Elf_(Verneed)) > end) {\n\t\t\tgoto beach;\n\t\t}\n\t\tElf_(Verneed) *entry = &vvn;\n\t\tchar key[32] = {0};\n\t\tsdb_version = sdb_new0 ();\n\t\tif (!sdb_version) {\n\t\t\tgoto beach;\n\t\t}\n\t\tj = 0;\n\t\tvvn.vn_version = READ16 (vstart, j)\n\t\tvvn.vn_cnt = READ16 (vstart, j)\n\t\tvvn.vn_file = READ32 (vstart, j)\n\t\tvvn.vn_aux = READ32 (vstart, j)\n\t\tvvn.vn_next = READ32 (vstart, j)", "\t\tsdb_num_set (sdb_version, \"vn_version\", entry->vn_version, 0);\n\t\tsdb_num_set (sdb_version, \"idx\", i, 0);\n\t\tif (entry->vn_file > bin->dynstr_size) {\n\t\t\tgoto beach;\n\t\t}\n\t\t{\n\t\t\tchar *s = r_str_ndup (&bin->dynstr[entry->vn_file], 16);\n\t\t\tsdb_set (sdb_version, \"file_name\", s, 0);\n\t\t\tfree (s);\n\t\t}\n\t\tsdb_num_set (sdb_version, \"cnt\", entry->vn_cnt, 0);", "\t\tvstart += entry->vn_aux;", "\t\tfor (j = 0, isum = i + entry->vn_aux; j < entry->vn_cnt && vstart + sizeof (Elf_(Vernaux)) <= end; ++j) {\n\t\t\tint k;\n\t\t\tElf_(Vernaux) * aux = NULL;\n\t\t\tElf_(Vernaux) vaux = {0};\n\t\t\tsdb_vernaux = sdb_new0 ();\n\t\t\tif (!sdb_vernaux) {\n\t\t\t\tgoto beach;\n\t\t\t}\n\t\t\taux = (Elf_(Vernaux)*)&vaux;\n\t\t\tk = 0;\n\t\t\tvaux.vna_hash = READ32 (vstart, k)\n\t\t\tvaux.vna_flags = READ16 (vstart, k)\n\t\t\tvaux.vna_other = READ16 (vstart, k)\n\t\t\tvaux.vna_name = READ32 (vstart, k)\n\t\t\tvaux.vna_next = READ32 (vstart, k)\n\t\t\tif (aux->vna_name > bin->dynstr_size) {\n\t\t\t\tgoto beach;\n\t\t\t}\n\t\t\tsdb_num_set (sdb_vernaux, \"idx\", isum, 0);\n\t\t\tif (aux->vna_name > 0 && aux->vna_name + 8 < bin->dynstr_size) {\n\t\t\t\tchar name [16];\n\t\t\t\tstrncpy (name, &bin->dynstr[aux->vna_name], sizeof (name)-1);\n\t\t\t\tname[sizeof(name)-1] = 0;\n\t\t\t\tsdb_set (sdb_vernaux, \"name\", name, 0);\n\t\t\t}\n\t\t\tsdb_set (sdb_vernaux, \"flags\", get_ver_flags (aux->vna_flags), 0);\n\t\t\tsdb_num_set (sdb_vernaux, \"version\", aux->vna_other, 0);\n\t\t\tisum += aux->vna_next;\n\t\t\tvstart += aux->vna_next;\n\t\t\tsnprintf (key, sizeof (key), \"vernaux%d\", j);\n\t\t\tsdb_ns_set (sdb_version, key, sdb_vernaux);\n\t\t}\n\t\tif ((int)entry->vn_next < 0) {\n\t\t\tbprintf (\"Invalid vn_next\\n\");\n\t\t\tbreak;\n\t\t}\n\t\ti += entry->vn_next;\n\t\tsnprintf (key, sizeof (key), \"version%d\", cnt );\n\t\tsdb_ns_set (sdb, key, sdb_version);\n\t\t//if entry->vn_next is 0 it iterate infinitely\n\t\tif (!entry->vn_next) {\n\t\t\tbreak;\n\t\t}\n\t}\n\tfree (need);\n\treturn sdb;\nbeach:\n\tfree (need);\n\tsdb_free (sdb_vernaux);\n\tsdb_free (sdb_version);\n\tsdb_free (sdb);\n\treturn NULL;\n}" ]
[ 1, 1, 1, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 2499, "char_start": 2494, "chars": "32 vn" }, { "char_end": 2502, "char_start": 2500, "chars": "ux" }, { "char_end": 2572, "char_start": 2515, "chars": "aux;\n\t\tif (vnaux < 1) {\n\t\t\tgoto beach;\n\t\t}\n\t\tvstart += vn" } ], "deleted": [ { "char_end": 2493, "char_start": 2492, "chars": "v" }, { "char_end": 2498, "char_start": 2496, "chars": "rt" }, { "char_end": 2500, "char_start": 2499, "chars": "+" } ] }, "commit_link": "github.com/radare/radare2/commit/c6d0076c924891ad9948a62d89d0bcdaf965f0cd", "file_name": "libr/bin/format/elf/elf.c", "func_name": "store_versioninfo_gnu_verneed", "line_changes": { "added": [ { "char_end": 2520, "char_start": 2490, "line": "\t\tst32 vnaux = entry->vn_aux;\n", "line_no": 85 }, { "char_end": 2539, "char_start": 2520, "line": "\t\tif (vnaux < 1) {\n", "line_no": 86 }, { "char_end": 2554, "char_start": 2539, "line": "\t\t\tgoto beach;\n", "line_no": 87 }, { "char_end": 2558, "char_start": 2554, "line": "\t\t}\n", "line_no": 88 }, { "char_end": 2577, "char_start": 2558, "line": "\t\tvstart += vnaux;\n", "line_no": 89 } ], "deleted": [ { "char_end": 2517, "char_start": 2490, "line": "\t\tvstart += entry->vn_aux;\n", "line_no": 85 } ] }, "vul_type": "cwe-125" }
486
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static Sdb *store_versioninfo_gnu_verneed(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) {\n\tut8 *end, *need = NULL;\n\tconst char *section_name = \"\";\n\tElf_(Shdr) *link_shdr = NULL;\n\tconst char *link_section_name = \"\";\n\tSdb *sdb_vernaux = NULL;\n\tSdb *sdb_version = NULL;\n\tSdb *sdb = NULL;\n\tint i, cnt;", "\tif (!bin || !bin->dynstr) {\n\t\treturn NULL;\n\t}\n\tif (shdr->sh_link > bin->ehdr.e_shnum) {\n\t\treturn NULL;\n\t}\n\tif (shdr->sh_size < 1) {\n\t\treturn NULL;\n\t}\n\tsdb = sdb_new0 ();\n\tif (!sdb) {\n\t\treturn NULL;\n\t}\n\tlink_shdr = &bin->shdr[shdr->sh_link];\n\tif (bin->shstrtab && shdr->sh_name < bin->shstrtab_size) {\n\t\tsection_name = &bin->shstrtab[shdr->sh_name];\n\t}\n\tif (bin->shstrtab && link_shdr->sh_name < bin->shstrtab_size) {\n\t\tlink_section_name = &bin->shstrtab[link_shdr->sh_name];\n\t}\n\tif (!(need = (ut8*) calloc (R_MAX (1, shdr->sh_size), sizeof (ut8)))) {\n\t\tbprintf (\"Warning: Cannot allocate memory for Elf_(Verneed)\\n\");\n\t\tgoto beach;\n\t}\n\tend = need + shdr->sh_size;\n\tsdb_set (sdb, \"section_name\", section_name, 0);\n\tsdb_num_set (sdb, \"num_entries\", shdr->sh_info, 0);\n\tsdb_num_set (sdb, \"addr\", shdr->sh_addr, 0);\n\tsdb_num_set (sdb, \"offset\", shdr->sh_offset, 0);\n\tsdb_num_set (sdb, \"link\", shdr->sh_link, 0);\n\tsdb_set (sdb, \"link_section_name\", link_section_name, 0);", "\tif (shdr->sh_offset > bin->size || shdr->sh_offset + shdr->sh_size > bin->size) {\n\t\tgoto beach;\n\t}\n\tif (shdr->sh_offset + shdr->sh_size < shdr->sh_size) {\n\t\tgoto beach;\n\t}\n\ti = r_buf_read_at (bin->b, shdr->sh_offset, need, shdr->sh_size);\n\tif (i < 0)\n\t\tgoto beach;\n\t//XXX we should use DT_VERNEEDNUM instead of sh_info\n\t//TODO https://sourceware.org/ml/binutils/2014-11/msg00353.html\n\tfor (i = 0, cnt = 0; cnt < shdr->sh_info; ++cnt) {\n\t\tint j, isum;\n\t\tut8 *vstart = need + i;\n\t\tElf_(Verneed) vvn = {0};\n\t\tif (vstart + sizeof (Elf_(Verneed)) > end) {\n\t\t\tgoto beach;\n\t\t}\n\t\tElf_(Verneed) *entry = &vvn;\n\t\tchar key[32] = {0};\n\t\tsdb_version = sdb_new0 ();\n\t\tif (!sdb_version) {\n\t\t\tgoto beach;\n\t\t}\n\t\tj = 0;\n\t\tvvn.vn_version = READ16 (vstart, j)\n\t\tvvn.vn_cnt = READ16 (vstart, j)\n\t\tvvn.vn_file = READ32 (vstart, j)\n\t\tvvn.vn_aux = READ32 (vstart, j)\n\t\tvvn.vn_next = READ32 (vstart, j)", "\t\tsdb_num_set (sdb_version, \"vn_version\", entry->vn_version, 0);\n\t\tsdb_num_set (sdb_version, \"idx\", i, 0);\n\t\tif (entry->vn_file > bin->dynstr_size) {\n\t\t\tgoto beach;\n\t\t}\n\t\t{\n\t\t\tchar *s = r_str_ndup (&bin->dynstr[entry->vn_file], 16);\n\t\t\tsdb_set (sdb_version, \"file_name\", s, 0);\n\t\t\tfree (s);\n\t\t}\n\t\tsdb_num_set (sdb_version, \"cnt\", entry->vn_cnt, 0);", "\t\tst32 vnaux = entry->vn_aux;\n\t\tif (vnaux < 1) {\n\t\t\tgoto beach;\n\t\t}\n\t\tvstart += vnaux;", "\t\tfor (j = 0, isum = i + entry->vn_aux; j < entry->vn_cnt && vstart + sizeof (Elf_(Vernaux)) <= end; ++j) {\n\t\t\tint k;\n\t\t\tElf_(Vernaux) * aux = NULL;\n\t\t\tElf_(Vernaux) vaux = {0};\n\t\t\tsdb_vernaux = sdb_new0 ();\n\t\t\tif (!sdb_vernaux) {\n\t\t\t\tgoto beach;\n\t\t\t}\n\t\t\taux = (Elf_(Vernaux)*)&vaux;\n\t\t\tk = 0;\n\t\t\tvaux.vna_hash = READ32 (vstart, k)\n\t\t\tvaux.vna_flags = READ16 (vstart, k)\n\t\t\tvaux.vna_other = READ16 (vstart, k)\n\t\t\tvaux.vna_name = READ32 (vstart, k)\n\t\t\tvaux.vna_next = READ32 (vstart, k)\n\t\t\tif (aux->vna_name > bin->dynstr_size) {\n\t\t\t\tgoto beach;\n\t\t\t}\n\t\t\tsdb_num_set (sdb_vernaux, \"idx\", isum, 0);\n\t\t\tif (aux->vna_name > 0 && aux->vna_name + 8 < bin->dynstr_size) {\n\t\t\t\tchar name [16];\n\t\t\t\tstrncpy (name, &bin->dynstr[aux->vna_name], sizeof (name)-1);\n\t\t\t\tname[sizeof(name)-1] = 0;\n\t\t\t\tsdb_set (sdb_vernaux, \"name\", name, 0);\n\t\t\t}\n\t\t\tsdb_set (sdb_vernaux, \"flags\", get_ver_flags (aux->vna_flags), 0);\n\t\t\tsdb_num_set (sdb_vernaux, \"version\", aux->vna_other, 0);\n\t\t\tisum += aux->vna_next;\n\t\t\tvstart += aux->vna_next;\n\t\t\tsnprintf (key, sizeof (key), \"vernaux%d\", j);\n\t\t\tsdb_ns_set (sdb_version, key, sdb_vernaux);\n\t\t}\n\t\tif ((int)entry->vn_next < 0) {\n\t\t\tbprintf (\"Invalid vn_next\\n\");\n\t\t\tbreak;\n\t\t}\n\t\ti += entry->vn_next;\n\t\tsnprintf (key, sizeof (key), \"version%d\", cnt );\n\t\tsdb_ns_set (sdb, key, sdb_version);\n\t\t//if entry->vn_next is 0 it iterate infinitely\n\t\tif (!entry->vn_next) {\n\t\t\tbreak;\n\t\t}\n\t}\n\tfree (need);\n\treturn sdb;\nbeach:\n\tfree (need);\n\tsdb_free (sdb_vernaux);\n\tsdb_free (sdb_version);\n\tsdb_free (sdb);\n\treturn NULL;\n}" ]
[ 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 2499, "char_start": 2494, "chars": "32 vn" }, { "char_end": 2502, "char_start": 2500, "chars": "ux" }, { "char_end": 2572, "char_start": 2515, "chars": "aux;\n\t\tif (vnaux < 1) {\n\t\t\tgoto beach;\n\t\t}\n\t\tvstart += vn" } ], "deleted": [ { "char_end": 2493, "char_start": 2492, "chars": "v" }, { "char_end": 2498, "char_start": 2496, "chars": "rt" }, { "char_end": 2500, "char_start": 2499, "chars": "+" } ] }, "commit_link": "github.com/radare/radare2/commit/c6d0076c924891ad9948a62d89d0bcdaf965f0cd", "file_name": "libr/bin/format/elf/elf.c", "func_name": "store_versioninfo_gnu_verneed", "line_changes": { "added": [ { "char_end": 2520, "char_start": 2490, "line": "\t\tst32 vnaux = entry->vn_aux;\n", "line_no": 85 }, { "char_end": 2539, "char_start": 2520, "line": "\t\tif (vnaux < 1) {\n", "line_no": 86 }, { "char_end": 2554, "char_start": 2539, "line": "\t\t\tgoto beach;\n", "line_no": 87 }, { "char_end": 2558, "char_start": 2554, "line": "\t\t}\n", "line_no": 88 }, { "char_end": 2577, "char_start": 2558, "line": "\t\tvstart += vnaux;\n", "line_no": 89 } ], "deleted": [ { "char_end": 2517, "char_start": 2490, "line": "\t\tvstart += entry->vn_aux;\n", "line_no": 85 } ] }, "vul_type": "cwe-125" }
486
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static Image *ReadWPGImage(const ImageInfo *image_info,\n ExceptionInfo *exception)\n{\n typedef struct\n {\n size_t FileId;\n MagickOffsetType DataOffset;\n unsigned int ProductType;\n unsigned int FileType;\n unsigned char MajorVersion;\n unsigned char MinorVersion;\n unsigned int EncryptKey;\n unsigned int Reserved;\n } WPGHeader;", " typedef struct\n {\n unsigned char RecType;\n size_t RecordLength;\n } WPGRecord;", " typedef struct\n {\n unsigned char Class;\n unsigned char RecType;\n size_t Extension;\n size_t RecordLength;\n } WPG2Record;", " typedef struct\n {\n unsigned HorizontalUnits;\n unsigned VerticalUnits;\n unsigned char PosSizePrecision;\n } WPG2Start;", " typedef struct\n {\n unsigned int Width;\n unsigned int Height;\n unsigned int Depth;\n unsigned int HorzRes;\n unsigned int VertRes;\n } WPGBitmapType1;", " typedef struct\n {\n unsigned int Width;\n unsigned int Height;\n unsigned char Depth;\n unsigned char Compression;\n } WPG2BitmapType1;", " typedef struct\n {\n unsigned int RotAngle;\n unsigned int LowLeftX;\n unsigned int LowLeftY;\n unsigned int UpRightX;\n unsigned int UpRightY;\n unsigned int Width;\n unsigned int Height;\n unsigned int Depth;\n unsigned int HorzRes;\n unsigned int VertRes;\n } WPGBitmapType2;", " typedef struct\n {\n unsigned int StartIndex;\n unsigned int NumOfEntries;\n } WPGColorMapRec;", " /*\n typedef struct {\n size_t PS_unknown1;\n unsigned int PS_unknown2;\n unsigned int PS_unknown3;\n } WPGPSl1Record; \n */", " Image\n *image;", " unsigned int\n status;", " WPGHeader\n Header;", " WPGRecord\n Rec;", " WPG2Record\n Rec2;", " WPG2Start StartWPG;", " WPGBitmapType1\n BitmapHeader1;", " WPG2BitmapType1\n Bitmap2Header1;", " WPGBitmapType2\n BitmapHeader2;", " WPGColorMapRec\n WPG_Palette;", " int\n i,\n bpp,\n WPG2Flags;", " ssize_t\n ldblk;", " size_t\n one;", " unsigned char\n *BImgBuff;", " tCTM CTM; /*current transform matrix*/", " /*\n Open image file.\n */\n assert(image_info != (const ImageInfo *) NULL);\n assert(image_info->signature == MagickCoreSignature);\n assert(exception != (ExceptionInfo *) NULL);\n assert(exception->signature == MagickCoreSignature);\n one=1;\n image=AcquireImage(image_info,exception);\n image->depth=8;\n status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);\n if (status == MagickFalse)\n {\n image=DestroyImageList(image);\n return((Image *) NULL);\n }\n /*\n Read WPG image.\n */\n Header.FileId=ReadBlobLSBLong(image);\n Header.DataOffset=(MagickOffsetType) ReadBlobLSBLong(image);\n Header.ProductType=ReadBlobLSBShort(image);\n Header.FileType=ReadBlobLSBShort(image);\n Header.MajorVersion=ReadBlobByte(image);\n Header.MinorVersion=ReadBlobByte(image);\n Header.EncryptKey=ReadBlobLSBShort(image);\n Header.Reserved=ReadBlobLSBShort(image);", " if (Header.FileId!=0x435057FF || (Header.ProductType>>8)!=0x16)\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n if (Header.EncryptKey!=0)\n ThrowReaderException(CoderError,\"EncryptedWPGImageFileNotSupported\");", " image->columns = 1;\n image->rows = 1;\n image->colors = 0;\n bpp=0;\n BitmapHeader2.RotAngle=0;", " switch(Header.FileType)\n {\n case 1: /* WPG level 1 */\n while(!EOFBlob(image)) /* object parser loop */\n {\n (void) SeekBlob(image,Header.DataOffset,SEEK_SET);\n if(EOFBlob(image))\n break;", " Rec.RecType=(i=ReadBlobByte(image));\n if(i==EOF)\n break;\n Rd_WP_DWORD(image,&Rec.RecordLength);\n if(EOFBlob(image))\n break;", " Header.DataOffset=TellBlob(image)+Rec.RecordLength;", " switch(Rec.RecType)\n {\n case 0x0B: /* bitmap type 1 */\n BitmapHeader1.Width=ReadBlobLSBShort(image);\n BitmapHeader1.Height=ReadBlobLSBShort(image);\n if ((BitmapHeader1.Width == 0) || (BitmapHeader1.Height == 0))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n BitmapHeader1.Depth=ReadBlobLSBShort(image);\n BitmapHeader1.HorzRes=ReadBlobLSBShort(image);\n BitmapHeader1.VertRes=ReadBlobLSBShort(image);", " if(BitmapHeader1.HorzRes && BitmapHeader1.VertRes)\n {\n image->units=PixelsPerCentimeterResolution;\n image->resolution.x=BitmapHeader1.HorzRes/470.0;\n image->resolution.y=BitmapHeader1.VertRes/470.0;\n }\n image->columns=BitmapHeader1.Width;\n image->rows=BitmapHeader1.Height;\n bpp=BitmapHeader1.Depth;", " goto UnpackRaster;", " case 0x0E: /*Color palette */\n WPG_Palette.StartIndex=ReadBlobLSBShort(image);\n WPG_Palette.NumOfEntries=ReadBlobLSBShort(image);", " image->colors=WPG_Palette.NumOfEntries;\n if (!AcquireImageColormap(image,image->colors,exception))\n goto NoMemory;\n for (i=WPG_Palette.StartIndex;\n i < (int)WPG_Palette.NumOfEntries; i++)\n {\n image->colormap[i].red=ScaleCharToQuantum((unsigned char)\n ReadBlobByte(image));\n image->colormap[i].green=ScaleCharToQuantum((unsigned char)\n ReadBlobByte(image));\n image->colormap[i].blue=ScaleCharToQuantum((unsigned char)\n ReadBlobByte(image));\n }\n break;\n \n case 0x11: /* Start PS l1 */\n if(Rec.RecordLength > 8)\n image=ExtractPostscript(image,image_info,\n TellBlob(image)+8, /* skip PS header in the wpg */\n (ssize_t) Rec.RecordLength-8,exception);\n break; ", " case 0x14: /* bitmap type 2 */\n BitmapHeader2.RotAngle=ReadBlobLSBShort(image);\n BitmapHeader2.LowLeftX=ReadBlobLSBShort(image);\n BitmapHeader2.LowLeftY=ReadBlobLSBShort(image);\n BitmapHeader2.UpRightX=ReadBlobLSBShort(image);\n BitmapHeader2.UpRightY=ReadBlobLSBShort(image);\n BitmapHeader2.Width=ReadBlobLSBShort(image);\n BitmapHeader2.Height=ReadBlobLSBShort(image);\n if ((BitmapHeader2.Width == 0) || (BitmapHeader2.Height == 0))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n BitmapHeader2.Depth=ReadBlobLSBShort(image);\n BitmapHeader2.HorzRes=ReadBlobLSBShort(image);\n BitmapHeader2.VertRes=ReadBlobLSBShort(image);", " image->units=PixelsPerCentimeterResolution;\n image->page.width=(unsigned int)\n ((BitmapHeader2.LowLeftX-BitmapHeader2.UpRightX)/470.0);\n image->page.height=(unsigned int)\n ((BitmapHeader2.LowLeftX-BitmapHeader2.UpRightY)/470.0);\n image->page.x=(int) (BitmapHeader2.LowLeftX/470.0);\n image->page.y=(int) (BitmapHeader2.LowLeftX/470.0);\n if(BitmapHeader2.HorzRes && BitmapHeader2.VertRes)\n {\n image->resolution.x=BitmapHeader2.HorzRes/470.0;\n image->resolution.y=BitmapHeader2.VertRes/470.0;\n }\n image->columns=BitmapHeader2.Width;\n image->rows=BitmapHeader2.Height;\n bpp=BitmapHeader2.Depth;", " UnpackRaster: \n if ((image->colors == 0) && (bpp != 24))\n {\n image->colors=one << bpp;\n if (!AcquireImageColormap(image,image->colors,exception))\n {\n NoMemory:\n ThrowReaderException(ResourceLimitError,\n \"MemoryAllocationFailed\");\n }\n /* printf(\"Load default colormap \\n\"); */\n for (i=0; (i < (int) image->colors) && (i < 256); i++)\n { \n image->colormap[i].red=ScaleCharToQuantum(WPG1_Palette[i].Red);\n image->colormap[i].green=ScaleCharToQuantum(WPG1_Palette[i].Green);\n image->colormap[i].blue=ScaleCharToQuantum(WPG1_Palette[i].Blue);\n }\n }\n else\n {\n if (bpp < 24)\n if ( (image->colors < (one << bpp)) && (bpp != 24) )\n image->colormap=(PixelInfo *) ResizeQuantumMemory(\n image->colormap,(size_t) (one << bpp),\n sizeof(*image->colormap));\n }\n \n if (bpp == 1)\n {\n if(image->colormap[0].red==0 &&\n image->colormap[0].green==0 &&\n image->colormap[0].blue==0 &&\n image->colormap[1].red==0 &&\n image->colormap[1].green==0 &&\n image->colormap[1].blue==0)\n { /* fix crippled monochrome palette */\n image->colormap[1].red =\n image->colormap[1].green =\n image->colormap[1].blue = QuantumRange;\n }\n } ", " if(UnpackWPGRaster(image,bpp,exception) < 0)\n /* The raster cannot be unpacked */\n {\n DecompressionFailed:\n ThrowReaderException(CoderError,\"UnableToDecompressImage\");\n }", " if(Rec.RecType==0x14 && BitmapHeader2.RotAngle!=0 && !image_info->ping)\n { \n /* flop command */\n if(BitmapHeader2.RotAngle & 0x8000)\n {\n Image\n *flop_image;", " flop_image = FlopImage(image, exception);\n if (flop_image != (Image *) NULL) {\n DuplicateBlob(flop_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,flop_image);\n }\n }\n /* flip command */\n if(BitmapHeader2.RotAngle & 0x2000)\n {\n Image\n *flip_image;", " flip_image = FlipImage(image, exception);\n if (flip_image != (Image *) NULL) {\n DuplicateBlob(flip_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,flip_image); \n }\n }\n \n /* rotate command */\n if(BitmapHeader2.RotAngle & 0x0FFF)\n {\n Image\n *rotate_image;", " rotate_image=RotateImage(image,(BitmapHeader2.RotAngle &\n 0x0FFF), exception);\n if (rotate_image != (Image *) NULL) {\n DuplicateBlob(rotate_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,rotate_image); \n }\n } \n }", " /* Allocate next image structure. */\n AcquireNextImage(image_info,image,exception);\n image->depth=8;\n if (image->next == (Image *) NULL)\n goto Finish;\n image=SyncNextImageInList(image);\n image->columns=image->rows=0;\n image->colors=0;\n break;", " case 0x1B: /* Postscript l2 */\n if(Rec.RecordLength>0x3C)\n image=ExtractPostscript(image,image_info,\n TellBlob(image)+0x3C, /* skip PS l2 header in the wpg */\n (ssize_t) Rec.RecordLength-0x3C,exception);\n break;\n }\n }\n break;", " case 2: /* WPG level 2 */\n (void) memset(CTM,0,sizeof(CTM));\n StartWPG.PosSizePrecision = 0;\n while(!EOFBlob(image)) /* object parser loop */\n {\n (void) SeekBlob(image,Header.DataOffset,SEEK_SET);\n if(EOFBlob(image))\n break;", " Rec2.Class=(i=ReadBlobByte(image));\n if(i==EOF)\n break;\n Rec2.RecType=(i=ReadBlobByte(image));\n if(i==EOF)\n break;\n Rd_WP_DWORD(image,&Rec2.Extension);\n Rd_WP_DWORD(image,&Rec2.RecordLength);\n if(EOFBlob(image))\n break;", " Header.DataOffset=TellBlob(image)+Rec2.RecordLength;", " switch(Rec2.RecType)\n {\n case 1:\n StartWPG.HorizontalUnits=ReadBlobLSBShort(image);\n StartWPG.VerticalUnits=ReadBlobLSBShort(image);\n StartWPG.PosSizePrecision=ReadBlobByte(image);\n break;\n case 0x0C: /* Color palette */\n WPG_Palette.StartIndex=ReadBlobLSBShort(image);\n WPG_Palette.NumOfEntries=ReadBlobLSBShort(image);", " image->colors=WPG_Palette.NumOfEntries;\n if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)\n ThrowReaderException(ResourceLimitError,\n \"MemoryAllocationFailed\");\n for (i=WPG_Palette.StartIndex;\n i < (int)WPG_Palette.NumOfEntries; i++)\n {\n image->colormap[i].red=ScaleCharToQuantum((char)\n ReadBlobByte(image));\n image->colormap[i].green=ScaleCharToQuantum((char)\n ReadBlobByte(image));\n image->colormap[i].blue=ScaleCharToQuantum((char)\n ReadBlobByte(image));\n (void) ReadBlobByte(image); /*Opacity??*/\n }\n break;\n case 0x0E:\n Bitmap2Header1.Width=ReadBlobLSBShort(image);\n Bitmap2Header1.Height=ReadBlobLSBShort(image);\n if ((Bitmap2Header1.Width == 0) || (Bitmap2Header1.Height == 0))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n Bitmap2Header1.Depth=ReadBlobByte(image);\n Bitmap2Header1.Compression=ReadBlobByte(image);", " if(Bitmap2Header1.Compression > 1)\n continue; /*Unknown compression method */\n switch(Bitmap2Header1.Depth)\n {\n case 1:\n bpp=1;\n break;\n case 2:\n bpp=2;\n break;\n case 3:\n bpp=4;\n break;\n case 4:\n bpp=8;\n break;\n case 8:\n bpp=24;\n break;\n default:\n continue; /*Ignore raster with unknown depth*/\n }\n image->columns=Bitmap2Header1.Width;\n image->rows=Bitmap2Header1.Height; ", " if ((image->colors == 0) && (bpp != 24))\n {\n size_t\n one;", " one=1;\n image->colors=one << bpp;\n if (!AcquireImageColormap(image,image->colors,exception))\n goto NoMemory;\n }\n else\n {\n if(bpp < 24)\n if( image->colors<(one << bpp) && bpp!=24 )\n image->colormap=(PixelInfo *) ResizeQuantumMemory(\n image->colormap,(size_t) (one << bpp),\n sizeof(*image->colormap));\n }", "\n switch(Bitmap2Header1.Compression)\n {\n case 0: /*Uncompressed raster*/\n {\n ldblk=(ssize_t) ((bpp*image->columns+7)/8);\n BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t)", " ldblk,sizeof(*BImgBuff));", " if (BImgBuff == (unsigned char *) NULL)\n goto NoMemory;", " for(i=0; i< (ssize_t) image->rows; i++)\n {\n (void) ReadBlob(image,ldblk,BImgBuff);\n InsertRow(image,BImgBuff,i,bpp,exception);\n }", " if(BImgBuff)\n BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff);;\n break;\n }\n case 1: /*RLE for WPG2 */\n {\n if( UnpackWPG2Raster(image,bpp,exception) < 0)\n goto DecompressionFailed;\n break;\n } \n }", " if(CTM[0][0]<0 && !image_info->ping)\n { /*?? RotAngle=360-RotAngle;*/\n Image\n *flop_image;", " flop_image = FlopImage(image, exception);\n if (flop_image != (Image *) NULL) {\n DuplicateBlob(flop_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,flop_image);\n }\n /* Try to change CTM according to Flip - I am not sure, must be checked. \n Tx(0,0)=-1; Tx(1,0)=0; Tx(2,0)=0;\n Tx(0,1)= 0; Tx(1,1)=1; Tx(2,1)=0;\n Tx(0,2)=(WPG._2Rect.X_ur+WPG._2Rect.X_ll);\n Tx(1,2)=0; Tx(2,2)=1; */ \n }\n if(CTM[1][1]<0 && !image_info->ping)\n { /*?? RotAngle=360-RotAngle;*/\n Image\n *flip_image;", " flip_image = FlipImage(image, exception);\n if (flip_image != (Image *) NULL) {\n DuplicateBlob(flip_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,flip_image);\n }\n /* Try to change CTM according to Flip - I am not sure, must be checked.\n float_matrix Tx(3,3);\n Tx(0,0)= 1; Tx(1,0)= 0; Tx(2,0)=0;\n Tx(0,1)= 0; Tx(1,1)=-1; Tx(2,1)=0;\n Tx(0,2)= 0; Tx(1,2)=(WPG._2Rect.Y_ur+WPG._2Rect.Y_ll);\n Tx(2,2)=1; */ \n } \n ", " /* Allocate next image structure. */\n AcquireNextImage(image_info,image,exception);\n image->depth=8;\n if (image->next == (Image *) NULL)\n goto Finish;\n image=SyncNextImageInList(image);\n image->columns=image->rows=1;\n image->colors=0;\n break;", " case 0x12: /* Postscript WPG2*/\n i=ReadBlobLSBShort(image);\n if(Rec2.RecordLength > (unsigned int) i)\n image=ExtractPostscript(image,image_info,\n TellBlob(image)+i, /*skip PS header in the wpg2*/\n (ssize_t) (Rec2.RecordLength-i-2),exception);\n break;", " case 0x1B: /*bitmap rectangle*/\n WPG2Flags = LoadWPG2Flags(image,StartWPG.PosSizePrecision,NULL,&CTM);\n (void) WPG2Flags;\n break;\n }\n }", " break;", " default:\n {\n ThrowReaderException(CoderError,\"DataEncodingSchemeIsNotSupported\");\n }\n }\n status=SetImageExtent(image,image->columns,image->rows,exception);\n if (status == MagickFalse)\n return(DestroyImageList(image));", " Finish:\n (void) CloseBlob(image);", " {\n Image\n *p;", " ssize_t\n scene=0;", " /*\n Rewind list, removing any empty images while rewinding.\n */\n p=image;\n image=NULL;\n while (p != (Image *) NULL)\n {\n Image *tmp=p;\n if ((p->rows == 0) || (p->columns == 0)) {\n p=p->previous;\n DeleteImageFromList(&tmp);\n } else {\n image=p;\n p=p->previous;\n }\n }\n /*\n Fix scene numbers.\n */\n for (p=image; p != (Image *) NULL; p=p->next)\n p->scene=(size_t) scene++;\n }\n if (image == (Image *) NULL)\n ThrowReaderException(CorruptImageError,\n \"ImageFileDoesNotContainAnyImageData\");\n return(image);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 16172, "char_start": 16170, "chars": "+1" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/bef1e4f637d8f665bc133a9c6d30df08d983bc3a", "file_name": "coders/wpg.c", "func_name": "ReadWPGImage", "line_changes": { "added": [ { "char_end": 16193, "char_start": 16143, "line": " ldblk+1,sizeof(*BImgBuff));\n", "line_no": 485 } ], "deleted": [ { "char_end": 16191, "char_start": 16143, "line": " ldblk,sizeof(*BImgBuff));\n", "line_no": 485 } ] }, "vul_type": "cwe-125" }
487
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static Image *ReadWPGImage(const ImageInfo *image_info,\n ExceptionInfo *exception)\n{\n typedef struct\n {\n size_t FileId;\n MagickOffsetType DataOffset;\n unsigned int ProductType;\n unsigned int FileType;\n unsigned char MajorVersion;\n unsigned char MinorVersion;\n unsigned int EncryptKey;\n unsigned int Reserved;\n } WPGHeader;", " typedef struct\n {\n unsigned char RecType;\n size_t RecordLength;\n } WPGRecord;", " typedef struct\n {\n unsigned char Class;\n unsigned char RecType;\n size_t Extension;\n size_t RecordLength;\n } WPG2Record;", " typedef struct\n {\n unsigned HorizontalUnits;\n unsigned VerticalUnits;\n unsigned char PosSizePrecision;\n } WPG2Start;", " typedef struct\n {\n unsigned int Width;\n unsigned int Height;\n unsigned int Depth;\n unsigned int HorzRes;\n unsigned int VertRes;\n } WPGBitmapType1;", " typedef struct\n {\n unsigned int Width;\n unsigned int Height;\n unsigned char Depth;\n unsigned char Compression;\n } WPG2BitmapType1;", " typedef struct\n {\n unsigned int RotAngle;\n unsigned int LowLeftX;\n unsigned int LowLeftY;\n unsigned int UpRightX;\n unsigned int UpRightY;\n unsigned int Width;\n unsigned int Height;\n unsigned int Depth;\n unsigned int HorzRes;\n unsigned int VertRes;\n } WPGBitmapType2;", " typedef struct\n {\n unsigned int StartIndex;\n unsigned int NumOfEntries;\n } WPGColorMapRec;", " /*\n typedef struct {\n size_t PS_unknown1;\n unsigned int PS_unknown2;\n unsigned int PS_unknown3;\n } WPGPSl1Record; \n */", " Image\n *image;", " unsigned int\n status;", " WPGHeader\n Header;", " WPGRecord\n Rec;", " WPG2Record\n Rec2;", " WPG2Start StartWPG;", " WPGBitmapType1\n BitmapHeader1;", " WPG2BitmapType1\n Bitmap2Header1;", " WPGBitmapType2\n BitmapHeader2;", " WPGColorMapRec\n WPG_Palette;", " int\n i,\n bpp,\n WPG2Flags;", " ssize_t\n ldblk;", " size_t\n one;", " unsigned char\n *BImgBuff;", " tCTM CTM; /*current transform matrix*/", " /*\n Open image file.\n */\n assert(image_info != (const ImageInfo *) NULL);\n assert(image_info->signature == MagickCoreSignature);\n assert(exception != (ExceptionInfo *) NULL);\n assert(exception->signature == MagickCoreSignature);\n one=1;\n image=AcquireImage(image_info,exception);\n image->depth=8;\n status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);\n if (status == MagickFalse)\n {\n image=DestroyImageList(image);\n return((Image *) NULL);\n }\n /*\n Read WPG image.\n */\n Header.FileId=ReadBlobLSBLong(image);\n Header.DataOffset=(MagickOffsetType) ReadBlobLSBLong(image);\n Header.ProductType=ReadBlobLSBShort(image);\n Header.FileType=ReadBlobLSBShort(image);\n Header.MajorVersion=ReadBlobByte(image);\n Header.MinorVersion=ReadBlobByte(image);\n Header.EncryptKey=ReadBlobLSBShort(image);\n Header.Reserved=ReadBlobLSBShort(image);", " if (Header.FileId!=0x435057FF || (Header.ProductType>>8)!=0x16)\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n if (Header.EncryptKey!=0)\n ThrowReaderException(CoderError,\"EncryptedWPGImageFileNotSupported\");", " image->columns = 1;\n image->rows = 1;\n image->colors = 0;\n bpp=0;\n BitmapHeader2.RotAngle=0;", " switch(Header.FileType)\n {\n case 1: /* WPG level 1 */\n while(!EOFBlob(image)) /* object parser loop */\n {\n (void) SeekBlob(image,Header.DataOffset,SEEK_SET);\n if(EOFBlob(image))\n break;", " Rec.RecType=(i=ReadBlobByte(image));\n if(i==EOF)\n break;\n Rd_WP_DWORD(image,&Rec.RecordLength);\n if(EOFBlob(image))\n break;", " Header.DataOffset=TellBlob(image)+Rec.RecordLength;", " switch(Rec.RecType)\n {\n case 0x0B: /* bitmap type 1 */\n BitmapHeader1.Width=ReadBlobLSBShort(image);\n BitmapHeader1.Height=ReadBlobLSBShort(image);\n if ((BitmapHeader1.Width == 0) || (BitmapHeader1.Height == 0))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n BitmapHeader1.Depth=ReadBlobLSBShort(image);\n BitmapHeader1.HorzRes=ReadBlobLSBShort(image);\n BitmapHeader1.VertRes=ReadBlobLSBShort(image);", " if(BitmapHeader1.HorzRes && BitmapHeader1.VertRes)\n {\n image->units=PixelsPerCentimeterResolution;\n image->resolution.x=BitmapHeader1.HorzRes/470.0;\n image->resolution.y=BitmapHeader1.VertRes/470.0;\n }\n image->columns=BitmapHeader1.Width;\n image->rows=BitmapHeader1.Height;\n bpp=BitmapHeader1.Depth;", " goto UnpackRaster;", " case 0x0E: /*Color palette */\n WPG_Palette.StartIndex=ReadBlobLSBShort(image);\n WPG_Palette.NumOfEntries=ReadBlobLSBShort(image);", " image->colors=WPG_Palette.NumOfEntries;\n if (!AcquireImageColormap(image,image->colors,exception))\n goto NoMemory;\n for (i=WPG_Palette.StartIndex;\n i < (int)WPG_Palette.NumOfEntries; i++)\n {\n image->colormap[i].red=ScaleCharToQuantum((unsigned char)\n ReadBlobByte(image));\n image->colormap[i].green=ScaleCharToQuantum((unsigned char)\n ReadBlobByte(image));\n image->colormap[i].blue=ScaleCharToQuantum((unsigned char)\n ReadBlobByte(image));\n }\n break;\n \n case 0x11: /* Start PS l1 */\n if(Rec.RecordLength > 8)\n image=ExtractPostscript(image,image_info,\n TellBlob(image)+8, /* skip PS header in the wpg */\n (ssize_t) Rec.RecordLength-8,exception);\n break; ", " case 0x14: /* bitmap type 2 */\n BitmapHeader2.RotAngle=ReadBlobLSBShort(image);\n BitmapHeader2.LowLeftX=ReadBlobLSBShort(image);\n BitmapHeader2.LowLeftY=ReadBlobLSBShort(image);\n BitmapHeader2.UpRightX=ReadBlobLSBShort(image);\n BitmapHeader2.UpRightY=ReadBlobLSBShort(image);\n BitmapHeader2.Width=ReadBlobLSBShort(image);\n BitmapHeader2.Height=ReadBlobLSBShort(image);\n if ((BitmapHeader2.Width == 0) || (BitmapHeader2.Height == 0))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n BitmapHeader2.Depth=ReadBlobLSBShort(image);\n BitmapHeader2.HorzRes=ReadBlobLSBShort(image);\n BitmapHeader2.VertRes=ReadBlobLSBShort(image);", " image->units=PixelsPerCentimeterResolution;\n image->page.width=(unsigned int)\n ((BitmapHeader2.LowLeftX-BitmapHeader2.UpRightX)/470.0);\n image->page.height=(unsigned int)\n ((BitmapHeader2.LowLeftX-BitmapHeader2.UpRightY)/470.0);\n image->page.x=(int) (BitmapHeader2.LowLeftX/470.0);\n image->page.y=(int) (BitmapHeader2.LowLeftX/470.0);\n if(BitmapHeader2.HorzRes && BitmapHeader2.VertRes)\n {\n image->resolution.x=BitmapHeader2.HorzRes/470.0;\n image->resolution.y=BitmapHeader2.VertRes/470.0;\n }\n image->columns=BitmapHeader2.Width;\n image->rows=BitmapHeader2.Height;\n bpp=BitmapHeader2.Depth;", " UnpackRaster: \n if ((image->colors == 0) && (bpp != 24))\n {\n image->colors=one << bpp;\n if (!AcquireImageColormap(image,image->colors,exception))\n {\n NoMemory:\n ThrowReaderException(ResourceLimitError,\n \"MemoryAllocationFailed\");\n }\n /* printf(\"Load default colormap \\n\"); */\n for (i=0; (i < (int) image->colors) && (i < 256); i++)\n { \n image->colormap[i].red=ScaleCharToQuantum(WPG1_Palette[i].Red);\n image->colormap[i].green=ScaleCharToQuantum(WPG1_Palette[i].Green);\n image->colormap[i].blue=ScaleCharToQuantum(WPG1_Palette[i].Blue);\n }\n }\n else\n {\n if (bpp < 24)\n if ( (image->colors < (one << bpp)) && (bpp != 24) )\n image->colormap=(PixelInfo *) ResizeQuantumMemory(\n image->colormap,(size_t) (one << bpp),\n sizeof(*image->colormap));\n }\n \n if (bpp == 1)\n {\n if(image->colormap[0].red==0 &&\n image->colormap[0].green==0 &&\n image->colormap[0].blue==0 &&\n image->colormap[1].red==0 &&\n image->colormap[1].green==0 &&\n image->colormap[1].blue==0)\n { /* fix crippled monochrome palette */\n image->colormap[1].red =\n image->colormap[1].green =\n image->colormap[1].blue = QuantumRange;\n }\n } ", " if(UnpackWPGRaster(image,bpp,exception) < 0)\n /* The raster cannot be unpacked */\n {\n DecompressionFailed:\n ThrowReaderException(CoderError,\"UnableToDecompressImage\");\n }", " if(Rec.RecType==0x14 && BitmapHeader2.RotAngle!=0 && !image_info->ping)\n { \n /* flop command */\n if(BitmapHeader2.RotAngle & 0x8000)\n {\n Image\n *flop_image;", " flop_image = FlopImage(image, exception);\n if (flop_image != (Image *) NULL) {\n DuplicateBlob(flop_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,flop_image);\n }\n }\n /* flip command */\n if(BitmapHeader2.RotAngle & 0x2000)\n {\n Image\n *flip_image;", " flip_image = FlipImage(image, exception);\n if (flip_image != (Image *) NULL) {\n DuplicateBlob(flip_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,flip_image); \n }\n }\n \n /* rotate command */\n if(BitmapHeader2.RotAngle & 0x0FFF)\n {\n Image\n *rotate_image;", " rotate_image=RotateImage(image,(BitmapHeader2.RotAngle &\n 0x0FFF), exception);\n if (rotate_image != (Image *) NULL) {\n DuplicateBlob(rotate_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,rotate_image); \n }\n } \n }", " /* Allocate next image structure. */\n AcquireNextImage(image_info,image,exception);\n image->depth=8;\n if (image->next == (Image *) NULL)\n goto Finish;\n image=SyncNextImageInList(image);\n image->columns=image->rows=0;\n image->colors=0;\n break;", " case 0x1B: /* Postscript l2 */\n if(Rec.RecordLength>0x3C)\n image=ExtractPostscript(image,image_info,\n TellBlob(image)+0x3C, /* skip PS l2 header in the wpg */\n (ssize_t) Rec.RecordLength-0x3C,exception);\n break;\n }\n }\n break;", " case 2: /* WPG level 2 */\n (void) memset(CTM,0,sizeof(CTM));\n StartWPG.PosSizePrecision = 0;\n while(!EOFBlob(image)) /* object parser loop */\n {\n (void) SeekBlob(image,Header.DataOffset,SEEK_SET);\n if(EOFBlob(image))\n break;", " Rec2.Class=(i=ReadBlobByte(image));\n if(i==EOF)\n break;\n Rec2.RecType=(i=ReadBlobByte(image));\n if(i==EOF)\n break;\n Rd_WP_DWORD(image,&Rec2.Extension);\n Rd_WP_DWORD(image,&Rec2.RecordLength);\n if(EOFBlob(image))\n break;", " Header.DataOffset=TellBlob(image)+Rec2.RecordLength;", " switch(Rec2.RecType)\n {\n case 1:\n StartWPG.HorizontalUnits=ReadBlobLSBShort(image);\n StartWPG.VerticalUnits=ReadBlobLSBShort(image);\n StartWPG.PosSizePrecision=ReadBlobByte(image);\n break;\n case 0x0C: /* Color palette */\n WPG_Palette.StartIndex=ReadBlobLSBShort(image);\n WPG_Palette.NumOfEntries=ReadBlobLSBShort(image);", " image->colors=WPG_Palette.NumOfEntries;\n if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)\n ThrowReaderException(ResourceLimitError,\n \"MemoryAllocationFailed\");\n for (i=WPG_Palette.StartIndex;\n i < (int)WPG_Palette.NumOfEntries; i++)\n {\n image->colormap[i].red=ScaleCharToQuantum((char)\n ReadBlobByte(image));\n image->colormap[i].green=ScaleCharToQuantum((char)\n ReadBlobByte(image));\n image->colormap[i].blue=ScaleCharToQuantum((char)\n ReadBlobByte(image));\n (void) ReadBlobByte(image); /*Opacity??*/\n }\n break;\n case 0x0E:\n Bitmap2Header1.Width=ReadBlobLSBShort(image);\n Bitmap2Header1.Height=ReadBlobLSBShort(image);\n if ((Bitmap2Header1.Width == 0) || (Bitmap2Header1.Height == 0))\n ThrowReaderException(CorruptImageError,\"ImproperImageHeader\");\n Bitmap2Header1.Depth=ReadBlobByte(image);\n Bitmap2Header1.Compression=ReadBlobByte(image);", " if(Bitmap2Header1.Compression > 1)\n continue; /*Unknown compression method */\n switch(Bitmap2Header1.Depth)\n {\n case 1:\n bpp=1;\n break;\n case 2:\n bpp=2;\n break;\n case 3:\n bpp=4;\n break;\n case 4:\n bpp=8;\n break;\n case 8:\n bpp=24;\n break;\n default:\n continue; /*Ignore raster with unknown depth*/\n }\n image->columns=Bitmap2Header1.Width;\n image->rows=Bitmap2Header1.Height; ", " if ((image->colors == 0) && (bpp != 24))\n {\n size_t\n one;", " one=1;\n image->colors=one << bpp;\n if (!AcquireImageColormap(image,image->colors,exception))\n goto NoMemory;\n }\n else\n {\n if(bpp < 24)\n if( image->colors<(one << bpp) && bpp!=24 )\n image->colormap=(PixelInfo *) ResizeQuantumMemory(\n image->colormap,(size_t) (one << bpp),\n sizeof(*image->colormap));\n }", "\n switch(Bitmap2Header1.Compression)\n {\n case 0: /*Uncompressed raster*/\n {\n ldblk=(ssize_t) ((bpp*image->columns+7)/8);\n BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t)", " ldblk+1,sizeof(*BImgBuff));", " if (BImgBuff == (unsigned char *) NULL)\n goto NoMemory;", " for(i=0; i< (ssize_t) image->rows; i++)\n {\n (void) ReadBlob(image,ldblk,BImgBuff);\n InsertRow(image,BImgBuff,i,bpp,exception);\n }", " if(BImgBuff)\n BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff);;\n break;\n }\n case 1: /*RLE for WPG2 */\n {\n if( UnpackWPG2Raster(image,bpp,exception) < 0)\n goto DecompressionFailed;\n break;\n } \n }", " if(CTM[0][0]<0 && !image_info->ping)\n { /*?? RotAngle=360-RotAngle;*/\n Image\n *flop_image;", " flop_image = FlopImage(image, exception);\n if (flop_image != (Image *) NULL) {\n DuplicateBlob(flop_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,flop_image);\n }\n /* Try to change CTM according to Flip - I am not sure, must be checked. \n Tx(0,0)=-1; Tx(1,0)=0; Tx(2,0)=0;\n Tx(0,1)= 0; Tx(1,1)=1; Tx(2,1)=0;\n Tx(0,2)=(WPG._2Rect.X_ur+WPG._2Rect.X_ll);\n Tx(1,2)=0; Tx(2,2)=1; */ \n }\n if(CTM[1][1]<0 && !image_info->ping)\n { /*?? RotAngle=360-RotAngle;*/\n Image\n *flip_image;", " flip_image = FlipImage(image, exception);\n if (flip_image != (Image *) NULL) {\n DuplicateBlob(flip_image,image);\n (void) RemoveLastImageFromList(&image);\n AppendImageToList(&image,flip_image);\n }\n /* Try to change CTM according to Flip - I am not sure, must be checked.\n float_matrix Tx(3,3);\n Tx(0,0)= 1; Tx(1,0)= 0; Tx(2,0)=0;\n Tx(0,1)= 0; Tx(1,1)=-1; Tx(2,1)=0;\n Tx(0,2)= 0; Tx(1,2)=(WPG._2Rect.Y_ur+WPG._2Rect.Y_ll);\n Tx(2,2)=1; */ \n } \n ", " /* Allocate next image structure. */\n AcquireNextImage(image_info,image,exception);\n image->depth=8;\n if (image->next == (Image *) NULL)\n goto Finish;\n image=SyncNextImageInList(image);\n image->columns=image->rows=1;\n image->colors=0;\n break;", " case 0x12: /* Postscript WPG2*/\n i=ReadBlobLSBShort(image);\n if(Rec2.RecordLength > (unsigned int) i)\n image=ExtractPostscript(image,image_info,\n TellBlob(image)+i, /*skip PS header in the wpg2*/\n (ssize_t) (Rec2.RecordLength-i-2),exception);\n break;", " case 0x1B: /*bitmap rectangle*/\n WPG2Flags = LoadWPG2Flags(image,StartWPG.PosSizePrecision,NULL,&CTM);\n (void) WPG2Flags;\n break;\n }\n }", " break;", " default:\n {\n ThrowReaderException(CoderError,\"DataEncodingSchemeIsNotSupported\");\n }\n }\n status=SetImageExtent(image,image->columns,image->rows,exception);\n if (status == MagickFalse)\n return(DestroyImageList(image));", " Finish:\n (void) CloseBlob(image);", " {\n Image\n *p;", " ssize_t\n scene=0;", " /*\n Rewind list, removing any empty images while rewinding.\n */\n p=image;\n image=NULL;\n while (p != (Image *) NULL)\n {\n Image *tmp=p;\n if ((p->rows == 0) || (p->columns == 0)) {\n p=p->previous;\n DeleteImageFromList(&tmp);\n } else {\n image=p;\n p=p->previous;\n }\n }\n /*\n Fix scene numbers.\n */\n for (p=image; p != (Image *) NULL; p=p->next)\n p->scene=(size_t) scene++;\n }\n if (image == (Image *) NULL)\n ThrowReaderException(CorruptImageError,\n \"ImageFileDoesNotContainAnyImageData\");\n return(image);\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 16172, "char_start": 16170, "chars": "+1" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/bef1e4f637d8f665bc133a9c6d30df08d983bc3a", "file_name": "coders/wpg.c", "func_name": "ReadWPGImage", "line_changes": { "added": [ { "char_end": 16193, "char_start": 16143, "line": " ldblk+1,sizeof(*BImgBuff));\n", "line_no": 485 } ], "deleted": [ { "char_end": 16191, "char_start": 16143, "line": " ldblk,sizeof(*BImgBuff));\n", "line_no": 485 } ] }, "vul_type": "cwe-125" }
487
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void gf_m2ts_process_pmt(GF_M2TS_Demuxer *ts, GF_M2TS_SECTION_ES *pmt, GF_List *sections, u8 table_id, u16 ex_table_id, u8 version_number, u8 last_section_number, u32 status)\n{\n\tu32 info_length, pos, desc_len, evt_type, nb_es,i;\n\tu32 nb_sections;\n\tu32 data_size;\n\tu32 nb_hevc, nb_hevc_temp, nb_shvc, nb_shvc_temp, nb_mhvc, nb_mhvc_temp;\n\tunsigned char *data;\n\tGF_M2TS_Section *section;\n\tGF_Err e = GF_OK;", "\t/*wait for the last section */\n\tif (!(status&GF_M2TS_TABLE_END)) return;", "\tnb_es = 0;", "\t/*skip if already received but no update detected (eg same data) */\n\tif ((status&GF_M2TS_TABLE_REPEAT) && !(status&GF_M2TS_TABLE_UPDATE)) {\n\t\tif (ts->on_event) ts->on_event(ts, GF_M2TS_EVT_PMT_REPEAT, pmt->program);\n\t\treturn;\n\t}", "\tif (pmt->sec->demux_restarted) {\n\t\tpmt->sec->demux_restarted = 0;\n\t\treturn;\n\t}\n\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"[MPEG-2 TS] PMT Found or updated\\n\"));", "\tnb_sections = gf_list_count(sections);\n\tif (nb_sections > 1) {\n\t\tGF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, (\"PMT on multiple sections not supported\\n\"));\n\t}", "\tsection = (GF_M2TS_Section *)gf_list_get(sections, 0);\n\tdata = section->data;\n\tdata_size = section->data_size;", "\tpmt->program->pcr_pid = ((data[0] & 0x1f) << 8) | data[1];", "\tinfo_length = ((data[2]&0xf)<<8) | data[3];\n\tif (info_length != 0) {\n\t\t/* ...Read Descriptors ... */\n\t\tu8 tag, len;\n\t\tu32 first_loop_len = 0;\n\t\ttag = data[4];\n\t\tlen = data[5];\n\t\twhile (info_length > first_loop_len) {\n\t\t\tif (tag == GF_M2TS_MPEG4_IOD_DESCRIPTOR) {\n\t\t\t\tu32 size;\n\t\t\t\tGF_BitStream *iod_bs;\n\t\t\t\tiod_bs = gf_bs_new((char *)data+8, len-2, GF_BITSTREAM_READ);\n\t\t\t\tif (pmt->program->pmt_iod) gf_odf_desc_del((GF_Descriptor *)pmt->program->pmt_iod);\n\t\t\t\te = gf_odf_parse_descriptor(iod_bs , (GF_Descriptor **) &pmt->program->pmt_iod, &size);\n\t\t\t\tgf_bs_del(iod_bs );\n\t\t\t\tif (e==GF_OK) {\n\t\t\t\t\t/*remember program number for service/program selection*/\n\t\t\t\t\tif (pmt->program->pmt_iod) pmt->program->pmt_iod->ServiceID = pmt->program->number;\n\t\t\t\t\t/*if empty IOD (freebox case), discard it and use dynamic declaration of object*/\n\t\t\t\t\tif (!gf_list_count(pmt->program->pmt_iod->ESDescriptors)) {\n\t\t\t\t\t\tgf_odf_desc_del((GF_Descriptor *)pmt->program->pmt_iod);\n\t\t\t\t\t\tpmt->program->pmt_iod = NULL;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (tag == GF_M2TS_METADATA_POINTER_DESCRIPTOR) {\n\t\t\t\tGF_BitStream *metadatapd_bs;\n\t\t\t\tGF_M2TS_MetadataPointerDescriptor *metapd;\n\t\t\t\tmetadatapd_bs = gf_bs_new((char *)data+6, len, GF_BITSTREAM_READ);\n\t\t\t\tmetapd = gf_m2ts_read_metadata_pointer_descriptor(metadatapd_bs, len);\n\t\t\t\tgf_bs_del(metadatapd_bs);\n\t\t\t\tif (metapd->application_format_identifier == GF_M2TS_META_ID3 &&\n\t\t\t\t metapd->format_identifier == GF_M2TS_META_ID3 &&\n\t\t\t\t metapd->carriage_flag == METADATA_CARRIAGE_SAME_TS) {\n\t\t\t\t\t/*HLS ID3 Metadata */\n\t\t\t\t\tpmt->program->metadata_pointer_descriptor = metapd;\n\t\t\t\t} else {\n\t\t\t\t\t/* don't know what to do with it for now, delete */\n\t\t\t\t\tgf_m2ts_metadata_pointer_descriptor_del(metapd);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Skipping descriptor (0x%x) and others not supported\\n\", tag));\n\t\t\t}\n\t\t\tfirst_loop_len += 2 + len;\n\t\t}\n\t}\n\tif (data_size <= 4 + info_length) return;\n\tdata += 4 + info_length;\n\tdata_size -= 4 + info_length;\n\tpos = 0;", "\t/* count de number of program related PMT received */\n\tfor(i=0; i<gf_list_count(ts->programs); i++) {\n\t\tGF_M2TS_Program *prog = (GF_M2TS_Program *)gf_list_get(ts->programs,i);\n\t\tif(prog->pmt_pid == pmt->pid) {\n\t\t\tbreak;\n\t\t}\n\t}", "\tnb_hevc = nb_hevc_temp = nb_shvc = nb_shvc_temp = nb_mhvc = nb_mhvc_temp = 0;\n\twhile (pos<data_size) {\n\t\tGF_M2TS_PES *pes = NULL;\n\t\tGF_M2TS_SECTION_ES *ses = NULL;\n\t\tGF_M2TS_ES *es = NULL;\n\t\tBool inherit_pcr = 0;\n\t\tu32 pid, stream_type, reg_desc_format;", "\t\tstream_type = data[0];\n\t\tpid = ((data[1] & 0x1f) << 8) | data[2];\n\t\tdesc_len = ((data[3] & 0xf) << 8) | data[4];", "\t\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"stream_type :%d \\n\",stream_type));\n\t\tswitch (stream_type) {", "\t\t/* PES */\n\t\tcase GF_M2TS_VIDEO_MPEG1:\n\t\tcase GF_M2TS_VIDEO_MPEG2:\n\t\tcase GF_M2TS_VIDEO_DCII:\n\t\tcase GF_M2TS_VIDEO_MPEG4:\n\t\tcase GF_M2TS_SYSTEMS_MPEG4_PES:\n\t\tcase GF_M2TS_VIDEO_H264:\n\t\tcase GF_M2TS_VIDEO_SVC:\n\t\tcase GF_M2TS_VIDEO_MVCD:\n\t\tcase GF_M2TS_VIDEO_HEVC:\n\t\tcase GF_M2TS_VIDEO_HEVC_MCTS:\n\t\tcase GF_M2TS_VIDEO_HEVC_TEMPORAL:\n\t\tcase GF_M2TS_VIDEO_SHVC:\n\t\tcase GF_M2TS_VIDEO_SHVC_TEMPORAL:\n\t\tcase GF_M2TS_VIDEO_MHVC:\n\t\tcase GF_M2TS_VIDEO_MHVC_TEMPORAL:\n\t\t\tinherit_pcr = 1;\n\t\tcase GF_M2TS_AUDIO_MPEG1:\n\t\tcase GF_M2TS_AUDIO_MPEG2:\n\t\tcase GF_M2TS_AUDIO_AAC:\n\t\tcase GF_M2TS_AUDIO_LATM_AAC:\n\t\tcase GF_M2TS_AUDIO_AC3:\n\t\tcase GF_M2TS_AUDIO_DTS:\n\t\tcase GF_M2TS_MHAS_MAIN:\n\t\tcase GF_M2TS_MHAS_AUX:\n\t\tcase GF_M2TS_SUBTITLE_DVB:\n\t\tcase GF_M2TS_METADATA_PES:\n\t\t\tGF_SAFEALLOC(pes, GF_M2TS_PES);\n\t\t\tif (!pes) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG2TS] Failed to allocate ES for pid %d\\n\", pid));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpes->cc = -1;\n\t\t\tpes->flags = GF_M2TS_ES_IS_PES;\n\t\t\tif (inherit_pcr)\n\t\t\t\tpes->flags |= GF_M2TS_INHERIT_PCR;\n\t\t\tes = (GF_M2TS_ES *)pes;\n\t\t\tbreak;\n\t\tcase GF_M2TS_PRIVATE_DATA:\n\t\t\tGF_SAFEALLOC(pes, GF_M2TS_PES);\n\t\t\tif (!pes) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG2TS] Failed to allocate ES for pid %d\\n\", pid));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpes->cc = -1;\n\t\t\tpes->flags = GF_M2TS_ES_IS_PES;\n\t\t\tes = (GF_M2TS_ES *)pes;\n\t\t\tbreak;\n\t\t/* Sections */\n\t\tcase GF_M2TS_SYSTEMS_MPEG4_SECTIONS:\n\t\t\tGF_SAFEALLOC(ses, GF_M2TS_SECTION_ES);\n\t\t\tif (!ses) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG2TS] Failed to allocate ES for pid %d\\n\", pid));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tes = (GF_M2TS_ES *)ses;\n\t\t\tes->flags |= GF_M2TS_ES_IS_SECTION;\n\t\t\t/* carriage of ISO_IEC_14496 data in sections */\n\t\t\tif (stream_type == GF_M2TS_SYSTEMS_MPEG4_SECTIONS) {\n\t\t\t\t/*MPEG-4 sections need to be fully checked: if one section is lost, this means we lost\n\t\t\t\tone SL packet in the AU so we must wait for the complete section again*/\n\t\t\t\tses->sec = gf_m2ts_section_filter_new(gf_m2ts_process_mpeg4section, 0);\n\t\t\t\t/*create OD container*/\n\t\t\t\tif (!pmt->program->additional_ods) {\n\t\t\t\t\tpmt->program->additional_ods = gf_list_new();\n\t\t\t\t\tts->has_4on2 = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;", "\t\tcase GF_M2TS_13818_6_ANNEX_A:\n\t\tcase GF_M2TS_13818_6_ANNEX_B:\n\t\tcase GF_M2TS_13818_6_ANNEX_C:\n\t\tcase GF_M2TS_13818_6_ANNEX_D:\n\t\tcase GF_M2TS_PRIVATE_SECTION:\n\t\tcase GF_M2TS_QUALITY_SEC:\n\t\tcase GF_M2TS_MORE_SEC:\n\t\t\tGF_SAFEALLOC(ses, GF_M2TS_SECTION_ES);\n\t\t\tif (!ses) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG2TS] Failed to allocate ES for pid %d\\n\", pid));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tes = (GF_M2TS_ES *)ses;\n\t\t\tes->flags |= GF_M2TS_ES_IS_SECTION;\n\t\t\tes->pid = pid;\n\t\t\tes->service_id = pmt->program->number;\n\t\t\tif (stream_type == GF_M2TS_PRIVATE_SECTION) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"AIT sections on pid %d\\n\", pid));\n\t\t\t} else if (stream_type == GF_M2TS_QUALITY_SEC) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"Quality metadata sections on pid %d\\n\", pid));\n\t\t\t} else if (stream_type == GF_M2TS_MORE_SEC) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"MORE sections on pid %d\\n\", pid));\n\t\t\t} else {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"stream type DSM CC user private sections on pid %d \\n\", pid));\n\t\t\t}\n\t\t\t/* NULL means: trigger the call to on_event with DVB_GENERAL type and the raw section as payload */\n\t\t\tses->sec = gf_m2ts_section_filter_new(NULL, 1);\n\t\t\t//ses->sec->service_id = pmt->program->number;\n\t\t\tbreak;", "\t\tcase GF_M2TS_MPE_SECTIONS:\n\t\t\tif (! ts->prefix_present) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"stream type MPE found : pid = %d \\n\", pid));\n#ifdef GPAC_ENABLE_MPE\n\t\t\t\tes = gf_dvb_mpe_section_new();\n\t\t\t\tif (es->flags & GF_M2TS_ES_IS_SECTION) {\n\t\t\t\t\t/* NULL means: trigger the call to on_event with DVB_GENERAL type and the raw section as payload */\n\t\t\t\t\t((GF_M2TS_SECTION_ES*)es)->sec = gf_m2ts_section_filter_new(NULL, 1);\n\t\t\t\t}\n#endif\n\t\t\t\tbreak;\n\t\t\t}", "\t\tdefault:\n\t\t\tGF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Stream type (0x%x) for PID %d not supported\\n\", stream_type, pid ) );\n\t\t\t//GF_LOG(/*GF_LOG_WARNING*/GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Stream type (0x%x) for PID %d not supported\\n\", stream_type, pid ) );\n\t\t\tbreak;\n\t\t}", "\t\tif (es) {\n\t\t\tes->stream_type = (stream_type==GF_M2TS_PRIVATE_DATA) ? 0 : stream_type;\n\t\t\tes->program = pmt->program;\n\t\t\tes->pid = pid;\n\t\t\tes->component_tag = -1;\n\t\t}", "\t\tpos += 5;\n\t\tdata += 5;", "\t\twhile (desc_len) {\n\t\t\tu8 tag = data[0];\n\t\t\tu32 len = data[1];\n\t\t\tif (es) {\n\t\t\t\tswitch (tag) {\n\t\t\t\tcase GF_M2TS_ISO_639_LANGUAGE_DESCRIPTOR:\n\t\t\t\t\tif (pes)\n\t\t\t\t\t\tpes->lang = GF_4CC(' ', data[2], data[3], data[4]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_MPEG4_SL_DESCRIPTOR:\n\t\t\t\t\tes->mpeg4_es_id = ( (u32) data[2] & 0x1f) << 8 | data[3];\n\t\t\t\t\tes->flags |= GF_M2TS_ES_IS_SL;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_REGISTRATION_DESCRIPTOR:\n\t\t\t\t\treg_desc_format = GF_4CC(data[2], data[3], data[4], data[5]);\n\t\t\t\t\t/*cf http://www.smpte-ra.org/mpegreg/mpegreg.html*/\n\t\t\t\t\tswitch (reg_desc_format) {\n\t\t\t\t\tcase GF_M2TS_RA_STREAM_AC3:\n\t\t\t\t\t\tes->stream_type = GF_M2TS_AUDIO_AC3;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase GF_M2TS_RA_STREAM_VC1:\n\t\t\t\t\t\tes->stream_type = GF_M2TS_VIDEO_VC1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase GF_M2TS_RA_STREAM_GPAC:\n\t\t\t\t\t\tif (len==8) {\n\t\t\t\t\t\t\tes->stream_type = GF_4CC(data[6], data[7], data[8], data[9]);\n\t\t\t\t\t\t\tes->flags |= GF_M2TS_GPAC_CODEC_ID;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"Unknown registration descriptor %s\\n\", gf_4cc_to_str(reg_desc_format) ));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_EAC3_DESCRIPTOR:\n\t\t\t\t\tes->stream_type = GF_M2TS_AUDIO_EC3;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_DATA_BROADCAST_ID_DESCRIPTOR:\n\t\t\t\t{\n\t\t\t\t\tu32 id = data[2]<<8 | data[3];\n\t\t\t\t\tif ((id == 0xB) && ses && !ses->sec) {\n\t\t\t\t\t\tses->sec = gf_m2ts_section_filter_new(NULL, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_SUBTITLING_DESCRIPTOR:\n\t\t\t\t\tif (pes) {\n\t\t\t\t\t\tpes->sub.language[0] = data[2];\n\t\t\t\t\t\tpes->sub.language[1] = data[3];\n\t\t\t\t\t\tpes->sub.language[2] = data[4];\n\t\t\t\t\t\tpes->sub.type = data[5];\n\t\t\t\t\t\tpes->sub.composition_page_id = (data[6]<<8) | data[7];\n\t\t\t\t\t\tpes->sub.ancillary_page_id = (data[8]<<8) | data[9];\n\t\t\t\t\t}\n\t\t\t\t\tes->stream_type = GF_M2TS_DVB_SUBTITLE;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_STREAM_IDENTIFIER_DESCRIPTOR:\n\t\t\t\t{\n\t\t\t\t\tes->component_tag = data[2];\n\t\t\t\t\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"Component Tag: %d on Program %d\\n\", es->component_tag, es->program->number));\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_TELETEXT_DESCRIPTOR:\n\t\t\t\t\tes->stream_type = GF_M2TS_DVB_TELETEXT;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_VBI_DATA_DESCRIPTOR:\n\t\t\t\t\tes->stream_type = GF_M2TS_DVB_VBI;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_HIERARCHY_DESCRIPTOR:\n\t\t\t\t\tif (pes) {\n\t\t\t\t\t\tu8 hierarchy_embedded_layer_index;\n\t\t\t\t\t\tGF_BitStream *hbs = gf_bs_new((const char *)data, data_size, GF_BITSTREAM_READ);\n\t\t\t\t\t\t/*u32 skip = */gf_bs_read_int(hbs, 16);\n\t\t\t\t\t\t/*u8 res1 = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 temp_scal = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 spatial_scal = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 quality_scal = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 hierarchy_type = */gf_bs_read_int(hbs, 4);\n\t\t\t\t\t\t/*u8 res2 = */gf_bs_read_int(hbs, 2);\n\t\t\t\t\t\t/*u8 hierarchy_layer_index = */gf_bs_read_int(hbs, 6);\n\t\t\t\t\t\t/*u8 tref_not_present = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 res3 = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\thierarchy_embedded_layer_index = gf_bs_read_int(hbs, 6);\n\t\t\t\t\t\t/*u8 res4 = */gf_bs_read_int(hbs, 2);\n\t\t\t\t\t\t/*u8 hierarchy_channel = */gf_bs_read_int(hbs, 6);\n\t\t\t\t\t\tgf_bs_del(hbs);", "\t\t\t\t\t\tpes->depends_on_pid = 1+hierarchy_embedded_layer_index;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_METADATA_DESCRIPTOR:\n\t\t\t\t{\n\t\t\t\t\tGF_BitStream *metadatad_bs;\n\t\t\t\t\tGF_M2TS_MetadataDescriptor *metad;\n\t\t\t\t\tmetadatad_bs = gf_bs_new((char *)data+2, len, GF_BITSTREAM_READ);\n\t\t\t\t\tmetad = gf_m2ts_read_metadata_descriptor(metadatad_bs, len);\n\t\t\t\t\tgf_bs_del(metadatad_bs);\n\t\t\t\t\tif (metad->application_format_identifier == GF_M2TS_META_ID3 &&\n\t\t\t\t\t metad->format_identifier == GF_M2TS_META_ID3) {\n\t\t\t\t\t\t/*HLS ID3 Metadata */\n\t\t\t\t\t\tif (pes) {\n\t\t\t\t\t\t\tpes->metadata_descriptor = metad;\n\t\t\t\t\t\t\tpes->stream_type = GF_M2TS_METADATA_ID3_HLS;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t/* don't know what to do with it for now, delete */\n\t\t\t\t\t\tgf_m2ts_metadata_descriptor_del(metad);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;", "\t\t\t\tdefault:\n\t\t\t\t\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"[MPEG-2 TS] skipping descriptor (0x%x) not supported\\n\", tag));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}", "\t\t\tdata += len+2;\n\t\t\tpos += len+2;\n\t\t\tif (desc_len < len+2) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Invalid PMT es descriptor size for PID %d\\n\", pid ) );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdesc_len-=len+2;\n\t\t}", "\t\tif (es && !es->stream_type) {\n\t\t\tgf_free(es);\n\t\t\tes = NULL;\n\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Private Stream type (0x%x) for PID %d not supported\\n\", stream_type, pid ) );\n\t\t}", "\t\tif (!es) continue;", "\t\tif (ts->ess[pid]) {\n\t\t\t//this is component reuse across programs, overwrite the previously declared stream ...\n\t\t\tif (status & GF_M2TS_TABLE_FOUND) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"[MPEG-2 TS] PID %d reused across programs %d and %d, not completely supported\\n\", pid, ts->ess[pid]->program->number, es->program->number ) );", "\t\t\t\t//add stream to program but don't reassign the pid table until the stream is playing (>GF_M2TS_PES_FRAMING_SKIP)\n\t\t\t\tgf_list_add(pmt->program->streams, es);\n\t\t\t\tif (!(es->flags & GF_M2TS_ES_IS_SECTION) ) gf_m2ts_set_pes_framing(pes, GF_M2TS_PES_FRAMING_SKIP);", "\t\t\t\tnb_es++;\n\t\t\t\t//skip assignment below\n\t\t\t\tes = NULL;\n\t\t\t}\n\t\t\t/*watchout for pmt update - FIXME this likely won't work in most cases*/\n\t\t\telse {", "\t\t\t\tGF_M2TS_ES *o_es = ts->ess[es->pid];", "\t\t\t\tif ((o_es->stream_type == es->stream_type)\n\t\t\t\t && ((o_es->flags & GF_M2TS_ES_STATIC_FLAGS_MASK) == (es->flags & GF_M2TS_ES_STATIC_FLAGS_MASK))\n\t\t\t\t && (o_es->mpeg4_es_id == es->mpeg4_es_id)\n\t\t\t\t && ((o_es->flags & GF_M2TS_ES_IS_SECTION) || ((GF_M2TS_PES *)o_es)->lang == ((GF_M2TS_PES *)es)->lang)\n\t\t\t\t ) {\n\t\t\t\t\tgf_free(es);\n\t\t\t\t\tes = NULL;\n\t\t\t\t} else {\n\t\t\t\t\tgf_m2ts_es_del(o_es, ts);\n\t\t\t\t\tts->ess[es->pid] = NULL;\n\t\t\t\t}\n\t\t\t}\n\t\t}", "\t\tif (es) {\n\t\t\tts->ess[es->pid] = es;\n\t\t\tgf_list_add(pmt->program->streams, es);\n\t\t\tif (!(es->flags & GF_M2TS_ES_IS_SECTION) ) gf_m2ts_set_pes_framing(pes, GF_M2TS_PES_FRAMING_SKIP);", "\t\t\tnb_es++;", "\t\t}", "\t\tif (es->stream_type == GF_M2TS_VIDEO_HEVC) nb_hevc++;\n\t\telse if (es->stream_type == GF_M2TS_VIDEO_HEVC_TEMPORAL) nb_hevc_temp++;\n\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC) nb_shvc++;\n\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC_TEMPORAL) nb_shvc_temp++;\n\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC) nb_mhvc++;\n\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC_TEMPORAL) nb_mhvc_temp++;", "\t}", "\t//Table 2-139, implied hierarchy indexes\n\tif (nb_hevc_temp + nb_shvc + nb_shvc_temp + nb_mhvc+ nb_mhvc_temp) {\n\t\tfor (i=0; i<gf_list_count(pmt->program->streams); i++) {\n\t\t\tGF_M2TS_PES *es = (GF_M2TS_PES *)gf_list_get(pmt->program->streams, i);\n\t\t\tif ( !(es->flags & GF_M2TS_ES_IS_PES)) continue;\n\t\t\tif (es->depends_on_pid) continue;", "\t\t\tswitch (es->stream_type) {\n\t\t\tcase GF_M2TS_VIDEO_HEVC_TEMPORAL:\n\t\t\t\tes->depends_on_pid = 1;\n\t\t\t\tbreak;\n\t\t\tcase GF_M2TS_VIDEO_SHVC:\n\t\t\t\tif (!nb_hevc_temp) es->depends_on_pid = 1;\n\t\t\t\telse es->depends_on_pid = 2;\n\t\t\t\tbreak;\n\t\t\tcase GF_M2TS_VIDEO_SHVC_TEMPORAL:\n\t\t\t\tes->depends_on_pid = 3;\n\t\t\t\tbreak;\n\t\t\tcase GF_M2TS_VIDEO_MHVC:\n\t\t\t\tif (!nb_hevc_temp) es->depends_on_pid = 1;\n\t\t\t\telse es->depends_on_pid = 2;\n\t\t\t\tbreak;\n\t\t\tcase GF_M2TS_VIDEO_MHVC_TEMPORAL:\n\t\t\t\tif (!nb_hevc_temp) es->depends_on_pid = 2;\n\t\t\t\telse es->depends_on_pid = 3;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}", "\tif (nb_es) {\n\t\tu32 i;", "\t\t//translate hierarchy descriptors indexes into PIDs - check whether the PMT-index rules are the same for HEVC\n\t\tfor (i=0; i<gf_list_count(pmt->program->streams); i++) {\n\t\t\tGF_M2TS_PES *an_es = NULL;\n\t\t\tGF_M2TS_PES *es = (GF_M2TS_PES *)gf_list_get(pmt->program->streams, i);\n\t\t\tif ( !(es->flags & GF_M2TS_ES_IS_PES)) continue;\n\t\t\tif (!es->depends_on_pid) continue;", "\t\t\t//fixeme we are not always assured that hierarchy_layer_index matches the stream index...\n\t\t\t//+1 is because our first stream is the PMT\n\t\t\tan_es = (GF_M2TS_PES *)gf_list_get(pmt->program->streams, es->depends_on_pid);\n\t\t\tif (an_es) {\n\t\t\t\tes->depends_on_pid = an_es->pid;\n\t\t\t} else {\n\t\t\t\tGF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, (\"[M2TS] Wrong dependency index in hierarchy descriptor, assuming non-scalable stream\\n\"));\n\t\t\t\tes->depends_on_pid = 0;\n\t\t\t}\n\t\t}", "\t\tevt_type = (status&GF_M2TS_TABLE_FOUND) ? GF_M2TS_EVT_PMT_FOUND : GF_M2TS_EVT_PMT_UPDATE;\n\t\tif (ts->on_event) ts->on_event(ts, evt_type, pmt->program);\n\t} else {\n\t\t/* if we found no new ES it's simply a repeat of the PMT */\n\t\tif (ts->on_event) ts->on_event(ts, GF_M2TS_EVT_PMT_REPEAT, pmt->program);\n\t}\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 14241, "char_start": 14240, "chars": "\t" }, { "char_end": 14298, "char_start": 14297, "chars": "\t" }, { "char_end": 14374, "char_start": 14373, "chars": "\t" }, { "char_end": 14438, "char_start": 14437, "chars": "\t" }, { "char_end": 14512, "char_start": 14511, "chars": "\t" }, { "char_end": 14576, "char_start": 14575, "chars": "\t" }, { "char_end": 14652, "char_start": 14648, "chars": "\n\t\t}" } ], "deleted": [ { "char_end": 14240, "char_start": 14239, "chars": "\t" }, { "char_end": 14244, "char_start": 14241, "chars": "}\n\n" } ] }, "commit_link": "github.com/gpac/gpac/commit/2320eb73afba753b39b7147be91f7be7afc0eeb7", "file_name": "src/media_tools/mpegts.c", "func_name": "gf_m2ts_process_pmt", "line_changes": { "added": [ { "char_end": 14297, "char_start": 14240, "line": "\t\t\tif (es->stream_type == GF_M2TS_VIDEO_HEVC) nb_hevc++;\n", "line_no": 414 }, { "char_end": 14373, "char_start": 14297, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_HEVC_TEMPORAL) nb_hevc_temp++;\n", "line_no": 415 }, { "char_end": 14435, "char_start": 14373, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC) nb_shvc++;\n", "line_no": 416 }, { "char_end": 14511, "char_start": 14435, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC_TEMPORAL) nb_shvc_temp++;\n", "line_no": 417 }, { "char_end": 14573, "char_start": 14511, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC) nb_mhvc++;\n", "line_no": 418 }, { "char_end": 14649, "char_start": 14573, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC_TEMPORAL) nb_mhvc_temp++;\n", "line_no": 419 }, { "char_end": 14653, "char_start": 14649, "line": "\t\t}\n", "line_no": 420 } ], "deleted": [ { "char_end": 14243, "char_start": 14239, "line": "\t\t}\n", "line_no": 413 }, { "char_end": 14300, "char_start": 14244, "line": "\t\tif (es->stream_type == GF_M2TS_VIDEO_HEVC) nb_hevc++;\n", "line_no": 415 }, { "char_end": 14375, "char_start": 14300, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_HEVC_TEMPORAL) nb_hevc_temp++;\n", "line_no": 416 }, { "char_end": 14436, "char_start": 14375, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC) nb_shvc++;\n", "line_no": 417 }, { "char_end": 14511, "char_start": 14436, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC_TEMPORAL) nb_shvc_temp++;\n", "line_no": 418 }, { "char_end": 14572, "char_start": 14511, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC) nb_mhvc++;\n", "line_no": 419 }, { "char_end": 14647, "char_start": 14572, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC_TEMPORAL) nb_mhvc_temp++;\n", "line_no": 420 } ] }, "vul_type": "cwe-125" }
488
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static void gf_m2ts_process_pmt(GF_M2TS_Demuxer *ts, GF_M2TS_SECTION_ES *pmt, GF_List *sections, u8 table_id, u16 ex_table_id, u8 version_number, u8 last_section_number, u32 status)\n{\n\tu32 info_length, pos, desc_len, evt_type, nb_es,i;\n\tu32 nb_sections;\n\tu32 data_size;\n\tu32 nb_hevc, nb_hevc_temp, nb_shvc, nb_shvc_temp, nb_mhvc, nb_mhvc_temp;\n\tunsigned char *data;\n\tGF_M2TS_Section *section;\n\tGF_Err e = GF_OK;", "\t/*wait for the last section */\n\tif (!(status&GF_M2TS_TABLE_END)) return;", "\tnb_es = 0;", "\t/*skip if already received but no update detected (eg same data) */\n\tif ((status&GF_M2TS_TABLE_REPEAT) && !(status&GF_M2TS_TABLE_UPDATE)) {\n\t\tif (ts->on_event) ts->on_event(ts, GF_M2TS_EVT_PMT_REPEAT, pmt->program);\n\t\treturn;\n\t}", "\tif (pmt->sec->demux_restarted) {\n\t\tpmt->sec->demux_restarted = 0;\n\t\treturn;\n\t}\n\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"[MPEG-2 TS] PMT Found or updated\\n\"));", "\tnb_sections = gf_list_count(sections);\n\tif (nb_sections > 1) {\n\t\tGF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, (\"PMT on multiple sections not supported\\n\"));\n\t}", "\tsection = (GF_M2TS_Section *)gf_list_get(sections, 0);\n\tdata = section->data;\n\tdata_size = section->data_size;", "\tpmt->program->pcr_pid = ((data[0] & 0x1f) << 8) | data[1];", "\tinfo_length = ((data[2]&0xf)<<8) | data[3];\n\tif (info_length != 0) {\n\t\t/* ...Read Descriptors ... */\n\t\tu8 tag, len;\n\t\tu32 first_loop_len = 0;\n\t\ttag = data[4];\n\t\tlen = data[5];\n\t\twhile (info_length > first_loop_len) {\n\t\t\tif (tag == GF_M2TS_MPEG4_IOD_DESCRIPTOR) {\n\t\t\t\tu32 size;\n\t\t\t\tGF_BitStream *iod_bs;\n\t\t\t\tiod_bs = gf_bs_new((char *)data+8, len-2, GF_BITSTREAM_READ);\n\t\t\t\tif (pmt->program->pmt_iod) gf_odf_desc_del((GF_Descriptor *)pmt->program->pmt_iod);\n\t\t\t\te = gf_odf_parse_descriptor(iod_bs , (GF_Descriptor **) &pmt->program->pmt_iod, &size);\n\t\t\t\tgf_bs_del(iod_bs );\n\t\t\t\tif (e==GF_OK) {\n\t\t\t\t\t/*remember program number for service/program selection*/\n\t\t\t\t\tif (pmt->program->pmt_iod) pmt->program->pmt_iod->ServiceID = pmt->program->number;\n\t\t\t\t\t/*if empty IOD (freebox case), discard it and use dynamic declaration of object*/\n\t\t\t\t\tif (!gf_list_count(pmt->program->pmt_iod->ESDescriptors)) {\n\t\t\t\t\t\tgf_odf_desc_del((GF_Descriptor *)pmt->program->pmt_iod);\n\t\t\t\t\t\tpmt->program->pmt_iod = NULL;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (tag == GF_M2TS_METADATA_POINTER_DESCRIPTOR) {\n\t\t\t\tGF_BitStream *metadatapd_bs;\n\t\t\t\tGF_M2TS_MetadataPointerDescriptor *metapd;\n\t\t\t\tmetadatapd_bs = gf_bs_new((char *)data+6, len, GF_BITSTREAM_READ);\n\t\t\t\tmetapd = gf_m2ts_read_metadata_pointer_descriptor(metadatapd_bs, len);\n\t\t\t\tgf_bs_del(metadatapd_bs);\n\t\t\t\tif (metapd->application_format_identifier == GF_M2TS_META_ID3 &&\n\t\t\t\t metapd->format_identifier == GF_M2TS_META_ID3 &&\n\t\t\t\t metapd->carriage_flag == METADATA_CARRIAGE_SAME_TS) {\n\t\t\t\t\t/*HLS ID3 Metadata */\n\t\t\t\t\tpmt->program->metadata_pointer_descriptor = metapd;\n\t\t\t\t} else {\n\t\t\t\t\t/* don't know what to do with it for now, delete */\n\t\t\t\t\tgf_m2ts_metadata_pointer_descriptor_del(metapd);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Skipping descriptor (0x%x) and others not supported\\n\", tag));\n\t\t\t}\n\t\t\tfirst_loop_len += 2 + len;\n\t\t}\n\t}\n\tif (data_size <= 4 + info_length) return;\n\tdata += 4 + info_length;\n\tdata_size -= 4 + info_length;\n\tpos = 0;", "\t/* count de number of program related PMT received */\n\tfor(i=0; i<gf_list_count(ts->programs); i++) {\n\t\tGF_M2TS_Program *prog = (GF_M2TS_Program *)gf_list_get(ts->programs,i);\n\t\tif(prog->pmt_pid == pmt->pid) {\n\t\t\tbreak;\n\t\t}\n\t}", "\tnb_hevc = nb_hevc_temp = nb_shvc = nb_shvc_temp = nb_mhvc = nb_mhvc_temp = 0;\n\twhile (pos<data_size) {\n\t\tGF_M2TS_PES *pes = NULL;\n\t\tGF_M2TS_SECTION_ES *ses = NULL;\n\t\tGF_M2TS_ES *es = NULL;\n\t\tBool inherit_pcr = 0;\n\t\tu32 pid, stream_type, reg_desc_format;", "\t\tstream_type = data[0];\n\t\tpid = ((data[1] & 0x1f) << 8) | data[2];\n\t\tdesc_len = ((data[3] & 0xf) << 8) | data[4];", "\t\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"stream_type :%d \\n\",stream_type));\n\t\tswitch (stream_type) {", "\t\t/* PES */\n\t\tcase GF_M2TS_VIDEO_MPEG1:\n\t\tcase GF_M2TS_VIDEO_MPEG2:\n\t\tcase GF_M2TS_VIDEO_DCII:\n\t\tcase GF_M2TS_VIDEO_MPEG4:\n\t\tcase GF_M2TS_SYSTEMS_MPEG4_PES:\n\t\tcase GF_M2TS_VIDEO_H264:\n\t\tcase GF_M2TS_VIDEO_SVC:\n\t\tcase GF_M2TS_VIDEO_MVCD:\n\t\tcase GF_M2TS_VIDEO_HEVC:\n\t\tcase GF_M2TS_VIDEO_HEVC_MCTS:\n\t\tcase GF_M2TS_VIDEO_HEVC_TEMPORAL:\n\t\tcase GF_M2TS_VIDEO_SHVC:\n\t\tcase GF_M2TS_VIDEO_SHVC_TEMPORAL:\n\t\tcase GF_M2TS_VIDEO_MHVC:\n\t\tcase GF_M2TS_VIDEO_MHVC_TEMPORAL:\n\t\t\tinherit_pcr = 1;\n\t\tcase GF_M2TS_AUDIO_MPEG1:\n\t\tcase GF_M2TS_AUDIO_MPEG2:\n\t\tcase GF_M2TS_AUDIO_AAC:\n\t\tcase GF_M2TS_AUDIO_LATM_AAC:\n\t\tcase GF_M2TS_AUDIO_AC3:\n\t\tcase GF_M2TS_AUDIO_DTS:\n\t\tcase GF_M2TS_MHAS_MAIN:\n\t\tcase GF_M2TS_MHAS_AUX:\n\t\tcase GF_M2TS_SUBTITLE_DVB:\n\t\tcase GF_M2TS_METADATA_PES:\n\t\t\tGF_SAFEALLOC(pes, GF_M2TS_PES);\n\t\t\tif (!pes) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG2TS] Failed to allocate ES for pid %d\\n\", pid));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpes->cc = -1;\n\t\t\tpes->flags = GF_M2TS_ES_IS_PES;\n\t\t\tif (inherit_pcr)\n\t\t\t\tpes->flags |= GF_M2TS_INHERIT_PCR;\n\t\t\tes = (GF_M2TS_ES *)pes;\n\t\t\tbreak;\n\t\tcase GF_M2TS_PRIVATE_DATA:\n\t\t\tGF_SAFEALLOC(pes, GF_M2TS_PES);\n\t\t\tif (!pes) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG2TS] Failed to allocate ES for pid %d\\n\", pid));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpes->cc = -1;\n\t\t\tpes->flags = GF_M2TS_ES_IS_PES;\n\t\t\tes = (GF_M2TS_ES *)pes;\n\t\t\tbreak;\n\t\t/* Sections */\n\t\tcase GF_M2TS_SYSTEMS_MPEG4_SECTIONS:\n\t\t\tGF_SAFEALLOC(ses, GF_M2TS_SECTION_ES);\n\t\t\tif (!ses) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG2TS] Failed to allocate ES for pid %d\\n\", pid));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tes = (GF_M2TS_ES *)ses;\n\t\t\tes->flags |= GF_M2TS_ES_IS_SECTION;\n\t\t\t/* carriage of ISO_IEC_14496 data in sections */\n\t\t\tif (stream_type == GF_M2TS_SYSTEMS_MPEG4_SECTIONS) {\n\t\t\t\t/*MPEG-4 sections need to be fully checked: if one section is lost, this means we lost\n\t\t\t\tone SL packet in the AU so we must wait for the complete section again*/\n\t\t\t\tses->sec = gf_m2ts_section_filter_new(gf_m2ts_process_mpeg4section, 0);\n\t\t\t\t/*create OD container*/\n\t\t\t\tif (!pmt->program->additional_ods) {\n\t\t\t\t\tpmt->program->additional_ods = gf_list_new();\n\t\t\t\t\tts->has_4on2 = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;", "\t\tcase GF_M2TS_13818_6_ANNEX_A:\n\t\tcase GF_M2TS_13818_6_ANNEX_B:\n\t\tcase GF_M2TS_13818_6_ANNEX_C:\n\t\tcase GF_M2TS_13818_6_ANNEX_D:\n\t\tcase GF_M2TS_PRIVATE_SECTION:\n\t\tcase GF_M2TS_QUALITY_SEC:\n\t\tcase GF_M2TS_MORE_SEC:\n\t\t\tGF_SAFEALLOC(ses, GF_M2TS_SECTION_ES);\n\t\t\tif (!ses) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG2TS] Failed to allocate ES for pid %d\\n\", pid));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tes = (GF_M2TS_ES *)ses;\n\t\t\tes->flags |= GF_M2TS_ES_IS_SECTION;\n\t\t\tes->pid = pid;\n\t\t\tes->service_id = pmt->program->number;\n\t\t\tif (stream_type == GF_M2TS_PRIVATE_SECTION) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"AIT sections on pid %d\\n\", pid));\n\t\t\t} else if (stream_type == GF_M2TS_QUALITY_SEC) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"Quality metadata sections on pid %d\\n\", pid));\n\t\t\t} else if (stream_type == GF_M2TS_MORE_SEC) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"MORE sections on pid %d\\n\", pid));\n\t\t\t} else {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"stream type DSM CC user private sections on pid %d \\n\", pid));\n\t\t\t}\n\t\t\t/* NULL means: trigger the call to on_event with DVB_GENERAL type and the raw section as payload */\n\t\t\tses->sec = gf_m2ts_section_filter_new(NULL, 1);\n\t\t\t//ses->sec->service_id = pmt->program->number;\n\t\t\tbreak;", "\t\tcase GF_M2TS_MPE_SECTIONS:\n\t\t\tif (! ts->prefix_present) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"stream type MPE found : pid = %d \\n\", pid));\n#ifdef GPAC_ENABLE_MPE\n\t\t\t\tes = gf_dvb_mpe_section_new();\n\t\t\t\tif (es->flags & GF_M2TS_ES_IS_SECTION) {\n\t\t\t\t\t/* NULL means: trigger the call to on_event with DVB_GENERAL type and the raw section as payload */\n\t\t\t\t\t((GF_M2TS_SECTION_ES*)es)->sec = gf_m2ts_section_filter_new(NULL, 1);\n\t\t\t\t}\n#endif\n\t\t\t\tbreak;\n\t\t\t}", "\t\tdefault:\n\t\t\tGF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Stream type (0x%x) for PID %d not supported\\n\", stream_type, pid ) );\n\t\t\t//GF_LOG(/*GF_LOG_WARNING*/GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Stream type (0x%x) for PID %d not supported\\n\", stream_type, pid ) );\n\t\t\tbreak;\n\t\t}", "\t\tif (es) {\n\t\t\tes->stream_type = (stream_type==GF_M2TS_PRIVATE_DATA) ? 0 : stream_type;\n\t\t\tes->program = pmt->program;\n\t\t\tes->pid = pid;\n\t\t\tes->component_tag = -1;\n\t\t}", "\t\tpos += 5;\n\t\tdata += 5;", "\t\twhile (desc_len) {\n\t\t\tu8 tag = data[0];\n\t\t\tu32 len = data[1];\n\t\t\tif (es) {\n\t\t\t\tswitch (tag) {\n\t\t\t\tcase GF_M2TS_ISO_639_LANGUAGE_DESCRIPTOR:\n\t\t\t\t\tif (pes)\n\t\t\t\t\t\tpes->lang = GF_4CC(' ', data[2], data[3], data[4]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_MPEG4_SL_DESCRIPTOR:\n\t\t\t\t\tes->mpeg4_es_id = ( (u32) data[2] & 0x1f) << 8 | data[3];\n\t\t\t\t\tes->flags |= GF_M2TS_ES_IS_SL;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_REGISTRATION_DESCRIPTOR:\n\t\t\t\t\treg_desc_format = GF_4CC(data[2], data[3], data[4], data[5]);\n\t\t\t\t\t/*cf http://www.smpte-ra.org/mpegreg/mpegreg.html*/\n\t\t\t\t\tswitch (reg_desc_format) {\n\t\t\t\t\tcase GF_M2TS_RA_STREAM_AC3:\n\t\t\t\t\t\tes->stream_type = GF_M2TS_AUDIO_AC3;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase GF_M2TS_RA_STREAM_VC1:\n\t\t\t\t\t\tes->stream_type = GF_M2TS_VIDEO_VC1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase GF_M2TS_RA_STREAM_GPAC:\n\t\t\t\t\t\tif (len==8) {\n\t\t\t\t\t\t\tes->stream_type = GF_4CC(data[6], data[7], data[8], data[9]);\n\t\t\t\t\t\t\tes->flags |= GF_M2TS_GPAC_CODEC_ID;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"Unknown registration descriptor %s\\n\", gf_4cc_to_str(reg_desc_format) ));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_EAC3_DESCRIPTOR:\n\t\t\t\t\tes->stream_type = GF_M2TS_AUDIO_EC3;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_DATA_BROADCAST_ID_DESCRIPTOR:\n\t\t\t\t{\n\t\t\t\t\tu32 id = data[2]<<8 | data[3];\n\t\t\t\t\tif ((id == 0xB) && ses && !ses->sec) {\n\t\t\t\t\t\tses->sec = gf_m2ts_section_filter_new(NULL, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_SUBTITLING_DESCRIPTOR:\n\t\t\t\t\tif (pes) {\n\t\t\t\t\t\tpes->sub.language[0] = data[2];\n\t\t\t\t\t\tpes->sub.language[1] = data[3];\n\t\t\t\t\t\tpes->sub.language[2] = data[4];\n\t\t\t\t\t\tpes->sub.type = data[5];\n\t\t\t\t\t\tpes->sub.composition_page_id = (data[6]<<8) | data[7];\n\t\t\t\t\t\tpes->sub.ancillary_page_id = (data[8]<<8) | data[9];\n\t\t\t\t\t}\n\t\t\t\t\tes->stream_type = GF_M2TS_DVB_SUBTITLE;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_STREAM_IDENTIFIER_DESCRIPTOR:\n\t\t\t\t{\n\t\t\t\t\tes->component_tag = data[2];\n\t\t\t\t\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"Component Tag: %d on Program %d\\n\", es->component_tag, es->program->number));\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_TELETEXT_DESCRIPTOR:\n\t\t\t\t\tes->stream_type = GF_M2TS_DVB_TELETEXT;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_DVB_VBI_DATA_DESCRIPTOR:\n\t\t\t\t\tes->stream_type = GF_M2TS_DVB_VBI;\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_HIERARCHY_DESCRIPTOR:\n\t\t\t\t\tif (pes) {\n\t\t\t\t\t\tu8 hierarchy_embedded_layer_index;\n\t\t\t\t\t\tGF_BitStream *hbs = gf_bs_new((const char *)data, data_size, GF_BITSTREAM_READ);\n\t\t\t\t\t\t/*u32 skip = */gf_bs_read_int(hbs, 16);\n\t\t\t\t\t\t/*u8 res1 = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 temp_scal = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 spatial_scal = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 quality_scal = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 hierarchy_type = */gf_bs_read_int(hbs, 4);\n\t\t\t\t\t\t/*u8 res2 = */gf_bs_read_int(hbs, 2);\n\t\t\t\t\t\t/*u8 hierarchy_layer_index = */gf_bs_read_int(hbs, 6);\n\t\t\t\t\t\t/*u8 tref_not_present = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\t/*u8 res3 = */gf_bs_read_int(hbs, 1);\n\t\t\t\t\t\thierarchy_embedded_layer_index = gf_bs_read_int(hbs, 6);\n\t\t\t\t\t\t/*u8 res4 = */gf_bs_read_int(hbs, 2);\n\t\t\t\t\t\t/*u8 hierarchy_channel = */gf_bs_read_int(hbs, 6);\n\t\t\t\t\t\tgf_bs_del(hbs);", "\t\t\t\t\t\tpes->depends_on_pid = 1+hierarchy_embedded_layer_index;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase GF_M2TS_METADATA_DESCRIPTOR:\n\t\t\t\t{\n\t\t\t\t\tGF_BitStream *metadatad_bs;\n\t\t\t\t\tGF_M2TS_MetadataDescriptor *metad;\n\t\t\t\t\tmetadatad_bs = gf_bs_new((char *)data+2, len, GF_BITSTREAM_READ);\n\t\t\t\t\tmetad = gf_m2ts_read_metadata_descriptor(metadatad_bs, len);\n\t\t\t\t\tgf_bs_del(metadatad_bs);\n\t\t\t\t\tif (metad->application_format_identifier == GF_M2TS_META_ID3 &&\n\t\t\t\t\t metad->format_identifier == GF_M2TS_META_ID3) {\n\t\t\t\t\t\t/*HLS ID3 Metadata */\n\t\t\t\t\t\tif (pes) {\n\t\t\t\t\t\t\tpes->metadata_descriptor = metad;\n\t\t\t\t\t\t\tpes->stream_type = GF_M2TS_METADATA_ID3_HLS;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t/* don't know what to do with it for now, delete */\n\t\t\t\t\t\tgf_m2ts_metadata_descriptor_del(metad);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;", "\t\t\t\tdefault:\n\t\t\t\t\tGF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, (\"[MPEG-2 TS] skipping descriptor (0x%x) not supported\\n\", tag));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}", "\t\t\tdata += len+2;\n\t\t\tpos += len+2;\n\t\t\tif (desc_len < len+2) {\n\t\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Invalid PMT es descriptor size for PID %d\\n\", pid ) );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdesc_len-=len+2;\n\t\t}", "\t\tif (es && !es->stream_type) {\n\t\t\tgf_free(es);\n\t\t\tes = NULL;\n\t\t\tGF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, (\"[MPEG-2 TS] Private Stream type (0x%x) for PID %d not supported\\n\", stream_type, pid ) );\n\t\t}", "\t\tif (!es) continue;", "\t\tif (ts->ess[pid]) {\n\t\t\t//this is component reuse across programs, overwrite the previously declared stream ...\n\t\t\tif (status & GF_M2TS_TABLE_FOUND) {\n\t\t\t\tGF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, (\"[MPEG-2 TS] PID %d reused across programs %d and %d, not completely supported\\n\", pid, ts->ess[pid]->program->number, es->program->number ) );", "\t\t\t\t//add stream to program but don't reassign the pid table until the stream is playing (>GF_M2TS_PES_FRAMING_SKIP)\n\t\t\t\tgf_list_add(pmt->program->streams, es);\n\t\t\t\tif (!(es->flags & GF_M2TS_ES_IS_SECTION) ) gf_m2ts_set_pes_framing(pes, GF_M2TS_PES_FRAMING_SKIP);", "\t\t\t\tnb_es++;\n\t\t\t\t//skip assignment below\n\t\t\t\tes = NULL;\n\t\t\t}\n\t\t\t/*watchout for pmt update - FIXME this likely won't work in most cases*/\n\t\t\telse {", "\t\t\t\tGF_M2TS_ES *o_es = ts->ess[es->pid];", "\t\t\t\tif ((o_es->stream_type == es->stream_type)\n\t\t\t\t && ((o_es->flags & GF_M2TS_ES_STATIC_FLAGS_MASK) == (es->flags & GF_M2TS_ES_STATIC_FLAGS_MASK))\n\t\t\t\t && (o_es->mpeg4_es_id == es->mpeg4_es_id)\n\t\t\t\t && ((o_es->flags & GF_M2TS_ES_IS_SECTION) || ((GF_M2TS_PES *)o_es)->lang == ((GF_M2TS_PES *)es)->lang)\n\t\t\t\t ) {\n\t\t\t\t\tgf_free(es);\n\t\t\t\t\tes = NULL;\n\t\t\t\t} else {\n\t\t\t\t\tgf_m2ts_es_del(o_es, ts);\n\t\t\t\t\tts->ess[es->pid] = NULL;\n\t\t\t\t}\n\t\t\t}\n\t\t}", "\t\tif (es) {\n\t\t\tts->ess[es->pid] = es;\n\t\t\tgf_list_add(pmt->program->streams, es);\n\t\t\tif (!(es->flags & GF_M2TS_ES_IS_SECTION) ) gf_m2ts_set_pes_framing(pes, GF_M2TS_PES_FRAMING_SKIP);", "\t\t\tnb_es++;", "\n\t\t\tif (es->stream_type == GF_M2TS_VIDEO_HEVC) nb_hevc++;\n\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_HEVC_TEMPORAL) nb_hevc_temp++;\n\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC) nb_shvc++;\n\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC_TEMPORAL) nb_shvc_temp++;\n\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC) nb_mhvc++;\n\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC_TEMPORAL) nb_mhvc_temp++;\n\t\t}", "\t}", "\t//Table 2-139, implied hierarchy indexes\n\tif (nb_hevc_temp + nb_shvc + nb_shvc_temp + nb_mhvc+ nb_mhvc_temp) {\n\t\tfor (i=0; i<gf_list_count(pmt->program->streams); i++) {\n\t\t\tGF_M2TS_PES *es = (GF_M2TS_PES *)gf_list_get(pmt->program->streams, i);\n\t\t\tif ( !(es->flags & GF_M2TS_ES_IS_PES)) continue;\n\t\t\tif (es->depends_on_pid) continue;", "\t\t\tswitch (es->stream_type) {\n\t\t\tcase GF_M2TS_VIDEO_HEVC_TEMPORAL:\n\t\t\t\tes->depends_on_pid = 1;\n\t\t\t\tbreak;\n\t\t\tcase GF_M2TS_VIDEO_SHVC:\n\t\t\t\tif (!nb_hevc_temp) es->depends_on_pid = 1;\n\t\t\t\telse es->depends_on_pid = 2;\n\t\t\t\tbreak;\n\t\t\tcase GF_M2TS_VIDEO_SHVC_TEMPORAL:\n\t\t\t\tes->depends_on_pid = 3;\n\t\t\t\tbreak;\n\t\t\tcase GF_M2TS_VIDEO_MHVC:\n\t\t\t\tif (!nb_hevc_temp) es->depends_on_pid = 1;\n\t\t\t\telse es->depends_on_pid = 2;\n\t\t\t\tbreak;\n\t\t\tcase GF_M2TS_VIDEO_MHVC_TEMPORAL:\n\t\t\t\tif (!nb_hevc_temp) es->depends_on_pid = 2;\n\t\t\t\telse es->depends_on_pid = 3;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}", "\tif (nb_es) {\n\t\tu32 i;", "\t\t//translate hierarchy descriptors indexes into PIDs - check whether the PMT-index rules are the same for HEVC\n\t\tfor (i=0; i<gf_list_count(pmt->program->streams); i++) {\n\t\t\tGF_M2TS_PES *an_es = NULL;\n\t\t\tGF_M2TS_PES *es = (GF_M2TS_PES *)gf_list_get(pmt->program->streams, i);\n\t\t\tif ( !(es->flags & GF_M2TS_ES_IS_PES)) continue;\n\t\t\tif (!es->depends_on_pid) continue;", "\t\t\t//fixeme we are not always assured that hierarchy_layer_index matches the stream index...\n\t\t\t//+1 is because our first stream is the PMT\n\t\t\tan_es = (GF_M2TS_PES *)gf_list_get(pmt->program->streams, es->depends_on_pid);\n\t\t\tif (an_es) {\n\t\t\t\tes->depends_on_pid = an_es->pid;\n\t\t\t} else {\n\t\t\t\tGF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, (\"[M2TS] Wrong dependency index in hierarchy descriptor, assuming non-scalable stream\\n\"));\n\t\t\t\tes->depends_on_pid = 0;\n\t\t\t}\n\t\t}", "\t\tevt_type = (status&GF_M2TS_TABLE_FOUND) ? GF_M2TS_EVT_PMT_FOUND : GF_M2TS_EVT_PMT_UPDATE;\n\t\tif (ts->on_event) ts->on_event(ts, evt_type, pmt->program);\n\t} else {\n\t\t/* if we found no new ES it's simply a repeat of the PMT */\n\t\tif (ts->on_event) ts->on_event(ts, GF_M2TS_EVT_PMT_REPEAT, pmt->program);\n\t}\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 14241, "char_start": 14240, "chars": "\t" }, { "char_end": 14298, "char_start": 14297, "chars": "\t" }, { "char_end": 14374, "char_start": 14373, "chars": "\t" }, { "char_end": 14438, "char_start": 14437, "chars": "\t" }, { "char_end": 14512, "char_start": 14511, "chars": "\t" }, { "char_end": 14576, "char_start": 14575, "chars": "\t" }, { "char_end": 14652, "char_start": 14648, "chars": "\n\t\t}" } ], "deleted": [ { "char_end": 14240, "char_start": 14239, "chars": "\t" }, { "char_end": 14244, "char_start": 14241, "chars": "}\n\n" } ] }, "commit_link": "github.com/gpac/gpac/commit/2320eb73afba753b39b7147be91f7be7afc0eeb7", "file_name": "src/media_tools/mpegts.c", "func_name": "gf_m2ts_process_pmt", "line_changes": { "added": [ { "char_end": 14297, "char_start": 14240, "line": "\t\t\tif (es->stream_type == GF_M2TS_VIDEO_HEVC) nb_hevc++;\n", "line_no": 414 }, { "char_end": 14373, "char_start": 14297, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_HEVC_TEMPORAL) nb_hevc_temp++;\n", "line_no": 415 }, { "char_end": 14435, "char_start": 14373, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC) nb_shvc++;\n", "line_no": 416 }, { "char_end": 14511, "char_start": 14435, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC_TEMPORAL) nb_shvc_temp++;\n", "line_no": 417 }, { "char_end": 14573, "char_start": 14511, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC) nb_mhvc++;\n", "line_no": 418 }, { "char_end": 14649, "char_start": 14573, "line": "\t\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC_TEMPORAL) nb_mhvc_temp++;\n", "line_no": 419 }, { "char_end": 14653, "char_start": 14649, "line": "\t\t}\n", "line_no": 420 } ], "deleted": [ { "char_end": 14243, "char_start": 14239, "line": "\t\t}\n", "line_no": 413 }, { "char_end": 14300, "char_start": 14244, "line": "\t\tif (es->stream_type == GF_M2TS_VIDEO_HEVC) nb_hevc++;\n", "line_no": 415 }, { "char_end": 14375, "char_start": 14300, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_HEVC_TEMPORAL) nb_hevc_temp++;\n", "line_no": 416 }, { "char_end": 14436, "char_start": 14375, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC) nb_shvc++;\n", "line_no": 417 }, { "char_end": 14511, "char_start": 14436, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_SHVC_TEMPORAL) nb_shvc_temp++;\n", "line_no": 418 }, { "char_end": 14572, "char_start": 14511, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC) nb_mhvc++;\n", "line_no": 419 }, { "char_end": 14647, "char_start": 14572, "line": "\t\telse if (es->stream_type == GF_M2TS_VIDEO_MHVC_TEMPORAL) nb_mhvc_temp++;\n", "line_no": 420 } ] }, "vul_type": "cwe-125" }
488
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "next_line(struct archive_read *a,\n const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl)\n{\n\tssize_t len;\n\tint quit;\n\t\n\tquit = 0;\n\tif (*avail == 0) {\n\t\t*nl = 0;\n\t\tlen = 0;\n\t} else\n\t\tlen = get_line_size(*b, *avail, nl);\n\t/*\n\t * Read bytes more while it does not reach the end of line.\n\t */\n\twhile (*nl == 0 && len == *avail && !quit) {\n\t\tssize_t diff = *ravail - *avail;\n\t\tsize_t nbytes_req = (*ravail+1023) & ~1023U;\n\t\tssize_t tested;", "\t\t/* Increase reading bytes if it is not enough to at least\n\t\t * new two lines. */\n\t\tif (nbytes_req < (size_t)*ravail + 160)\n\t\t\tnbytes_req <<= 1;", "\t\t*b = __archive_read_ahead(a, nbytes_req, avail);\n\t\tif (*b == NULL) {\n\t\t\tif (*ravail >= *avail)\n\t\t\t\treturn (0);\n\t\t\t/* Reading bytes reaches the end of file. */\n\t\t\t*b = __archive_read_ahead(a, *avail, avail);\n\t\t\tquit = 1;\n\t\t}\n\t\t*ravail = *avail;\n\t\t*b += diff;\n\t\t*avail -= diff;\n\t\ttested = len;/* Skip some bytes we already determinated. */", "\t\tlen = get_line_size(*b, *avail, nl);", "\t\tif (len >= 0)\n\t\t\tlen += tested;\n\t}\n\treturn (len);\n}" ]
[ 1, 1, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 963, "char_start": 957, "chars": " + len" }, { "char_end": 977, "char_start": 971, "chars": " - len" } ], "deleted": [] }, "commit_link": "github.com/libarchive/libarchive/commit/eec077f52bfa2d3f7103b4b74d52572ba8a15aca", "file_name": "libarchive/archive_read_support_format_mtree.c", "func_name": "next_line", "line_changes": { "added": [ { "char_end": 984, "char_start": 933, "line": "\t\tlen = get_line_size(*b + len, *avail - len, nl);\n", "line_no": 38 } ], "deleted": [ { "char_end": 972, "char_start": 933, "line": "\t\tlen = get_line_size(*b, *avail, nl);\n", "line_no": 38 } ] }, "vul_type": "cwe-125" }
489
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "next_line(struct archive_read *a,\n const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl)\n{\n\tssize_t len;\n\tint quit;\n\t\n\tquit = 0;\n\tif (*avail == 0) {\n\t\t*nl = 0;\n\t\tlen = 0;\n\t} else\n\t\tlen = get_line_size(*b, *avail, nl);\n\t/*\n\t * Read bytes more while it does not reach the end of line.\n\t */\n\twhile (*nl == 0 && len == *avail && !quit) {\n\t\tssize_t diff = *ravail - *avail;\n\t\tsize_t nbytes_req = (*ravail+1023) & ~1023U;\n\t\tssize_t tested;", "\t\t/* Increase reading bytes if it is not enough to at least\n\t\t * new two lines. */\n\t\tif (nbytes_req < (size_t)*ravail + 160)\n\t\t\tnbytes_req <<= 1;", "\t\t*b = __archive_read_ahead(a, nbytes_req, avail);\n\t\tif (*b == NULL) {\n\t\t\tif (*ravail >= *avail)\n\t\t\t\treturn (0);\n\t\t\t/* Reading bytes reaches the end of file. */\n\t\t\t*b = __archive_read_ahead(a, *avail, avail);\n\t\t\tquit = 1;\n\t\t}\n\t\t*ravail = *avail;\n\t\t*b += diff;\n\t\t*avail -= diff;\n\t\ttested = len;/* Skip some bytes we already determinated. */", "\t\tlen = get_line_size(*b + len, *avail - len, nl);", "\t\tif (len >= 0)\n\t\t\tlen += tested;\n\t}\n\treturn (len);\n}" ]
[ 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 963, "char_start": 957, "chars": " + len" }, { "char_end": 977, "char_start": 971, "chars": " - len" } ], "deleted": [] }, "commit_link": "github.com/libarchive/libarchive/commit/eec077f52bfa2d3f7103b4b74d52572ba8a15aca", "file_name": "libarchive/archive_read_support_format_mtree.c", "func_name": "next_line", "line_changes": { "added": [ { "char_end": 984, "char_start": 933, "line": "\t\tlen = get_line_size(*b + len, *avail - len, nl);\n", "line_no": 38 } ], "deleted": [ { "char_end": 972, "char_start": 933, "line": "\t\tlen = get_line_size(*b, *avail, nl);\n", "line_no": 38 } ] }, "vul_type": "cwe-125" }
489
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "x86_reg X86_insn_reg_intel(unsigned int id, enum cs_ac_type *access)\n{", "", "\tunsigned int first = 0;\n\tunsigned int last = ARR_SIZE(insn_regs_intel) - 1;", "\tunsigned int mid = ARR_SIZE(insn_regs_intel) / 2;", "\n\tif (!intel_regs_sorted) {\n\t\tmemcpy(insn_regs_intel_sorted, insn_regs_intel,\n\t\t\t\tsizeof(insn_regs_intel_sorted));\n\t\tqsort(insn_regs_intel_sorted,\n\t\t\t\tARR_SIZE(insn_regs_intel_sorted),\n\t\t\t\tsizeof(struct insn_reg), regs_cmp);\n\t\tintel_regs_sorted = true;\n\t}\n", "", "\twhile (first <= last) {", "", "\t\tif (insn_regs_intel_sorted[mid].insn < id) {\n\t\t\tfirst = mid + 1;\n\t\t} else if (insn_regs_intel_sorted[mid].insn == id) {\n\t\t\tif (access) {\n\t\t\t\t*access = insn_regs_intel_sorted[mid].access;\n\t\t\t}\n\t\t\treturn insn_regs_intel_sorted[mid].reg;\n\t\t} else {\n\t\t\tif (mid == 0)\n\t\t\t\tbreak;\n\t\t\tlast = mid - 1;\n\t\t}", "\t\tmid = (first + last) / 2;", "\t}", "\t// not found\n\treturn 0;\n}" ]
[ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 112, "char_start": 72, "chars": "static bool intel_regs_sorted = false;\n\t" }, { "char_end": 570, "char_start": 465, "chars": "if (insn_regs_intel_sorted[0].insn > id ||\n\t\t\tinsn_regs_intel_sorted[last].insn < id) {\n\t\treturn 0;\n\t}\n\n\t" }, { "char_end": 621, "char_start": 593, "chars": "\n\t\tmid = (first + last) / 2;" } ], "deleted": [ { "char_end": 197, "char_start": 165, "chars": " = ARR_SIZE(insn_regs_intel) / 2" }, { "char_end": 807, "char_start": 779, "chars": "\n\t\tmid = (first + last) / 2;" } ] }, "commit_link": "github.com/aquynh/capstone/commit/87a25bb543c8e4c09b48d4b4a6c7db31ce58df06", "file_name": "arch/X86/X86Mapping.c", "func_name": "X86_insn_reg_intel", "line_changes": { "added": [ { "char_end": 111, "char_start": 71, "line": "\tstatic bool intel_regs_sorted = false;\n", "line_no": 3 }, { "char_end": 207, "char_start": 188, "line": "\tunsigned int mid;\n", "line_no": 6 }, { "char_end": 508, "char_start": 464, "line": "\tif (insn_regs_intel_sorted[0].insn > id ||\n", "line_no": 17 }, { "char_end": 553, "char_start": 508, "line": "\t\t\tinsn_regs_intel_sorted[last].insn < id) {\n", "line_no": 18 }, { "char_end": 565, "char_start": 553, "line": "\t\treturn 0;\n", "line_no": 19 }, { "char_end": 568, "char_start": 565, "line": "\t}\n", "line_no": 20 }, { "char_end": 569, "char_start": 568, "line": "\n", "line_no": 21 }, { "char_end": 622, "char_start": 594, "line": "\t\tmid = (first + last) / 2;\n", "line_no": 23 } ], "deleted": [ { "char_end": 199, "char_start": 148, "line": "\tunsigned int mid = ARR_SIZE(insn_regs_intel) / 2;\n", "line_no": 5 }, { "char_end": 808, "char_start": 780, "line": "\t\tmid = (first + last) / 2;\n", "line_no": 29 } ] }, "vul_type": "cwe-125" }
490
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "x86_reg X86_insn_reg_intel(unsigned int id, enum cs_ac_type *access)\n{", "\tstatic bool intel_regs_sorted = false;", "\tunsigned int first = 0;\n\tunsigned int last = ARR_SIZE(insn_regs_intel) - 1;", "\tunsigned int mid;", "\n\tif (!intel_regs_sorted) {\n\t\tmemcpy(insn_regs_intel_sorted, insn_regs_intel,\n\t\t\t\tsizeof(insn_regs_intel_sorted));\n\t\tqsort(insn_regs_intel_sorted,\n\t\t\t\tARR_SIZE(insn_regs_intel_sorted),\n\t\t\t\tsizeof(struct insn_reg), regs_cmp);\n\t\tintel_regs_sorted = true;\n\t}\n", "\tif (insn_regs_intel_sorted[0].insn > id ||\n\t\t\tinsn_regs_intel_sorted[last].insn < id) {\n\t\treturn 0;\n\t}\n", "\twhile (first <= last) {", "\t\tmid = (first + last) / 2;", "\t\tif (insn_regs_intel_sorted[mid].insn < id) {\n\t\t\tfirst = mid + 1;\n\t\t} else if (insn_regs_intel_sorted[mid].insn == id) {\n\t\t\tif (access) {\n\t\t\t\t*access = insn_regs_intel_sorted[mid].access;\n\t\t\t}\n\t\t\treturn insn_regs_intel_sorted[mid].reg;\n\t\t} else {\n\t\t\tif (mid == 0)\n\t\t\t\tbreak;\n\t\t\tlast = mid - 1;\n\t\t}", "", "\t}", "\t// not found\n\treturn 0;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 112, "char_start": 72, "chars": "static bool intel_regs_sorted = false;\n\t" }, { "char_end": 570, "char_start": 465, "chars": "if (insn_regs_intel_sorted[0].insn > id ||\n\t\t\tinsn_regs_intel_sorted[last].insn < id) {\n\t\treturn 0;\n\t}\n\n\t" }, { "char_end": 621, "char_start": 593, "chars": "\n\t\tmid = (first + last) / 2;" } ], "deleted": [ { "char_end": 197, "char_start": 165, "chars": " = ARR_SIZE(insn_regs_intel) / 2" }, { "char_end": 807, "char_start": 779, "chars": "\n\t\tmid = (first + last) / 2;" } ] }, "commit_link": "github.com/aquynh/capstone/commit/87a25bb543c8e4c09b48d4b4a6c7db31ce58df06", "file_name": "arch/X86/X86Mapping.c", "func_name": "X86_insn_reg_intel", "line_changes": { "added": [ { "char_end": 111, "char_start": 71, "line": "\tstatic bool intel_regs_sorted = false;\n", "line_no": 3 }, { "char_end": 207, "char_start": 188, "line": "\tunsigned int mid;\n", "line_no": 6 }, { "char_end": 508, "char_start": 464, "line": "\tif (insn_regs_intel_sorted[0].insn > id ||\n", "line_no": 17 }, { "char_end": 553, "char_start": 508, "line": "\t\t\tinsn_regs_intel_sorted[last].insn < id) {\n", "line_no": 18 }, { "char_end": 565, "char_start": 553, "line": "\t\treturn 0;\n", "line_no": 19 }, { "char_end": 568, "char_start": 565, "line": "\t}\n", "line_no": 20 }, { "char_end": 569, "char_start": 568, "line": "\n", "line_no": 21 }, { "char_end": 622, "char_start": 594, "line": "\t\tmid = (first + last) / 2;\n", "line_no": 23 } ], "deleted": [ { "char_end": 199, "char_start": 148, "line": "\tunsigned int mid = ARR_SIZE(insn_regs_intel) / 2;\n", "line_no": 5 }, { "char_end": 808, "char_start": 780, "line": "\t\tmid = (first + last) / 2;\n", "line_no": 29 } ] }, "vul_type": "cwe-125" }
490
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "R_API RBinJavaAttrInfo *r_bin_java_line_number_table_attr_new(ut8 *buffer, ut64 sz, ut64 buf_offset) {\n\tut32 i = 0;\n\tut64 curpos, offset = 0;\n\tRBinJavaLineNumberAttribute *lnattr;\n\tRBinJavaAttrInfo *attr = r_bin_java_default_attr_new (buffer, sz, buf_offset);\n\tif (!attr) {\n\t\treturn NULL;\n\t}\n\toffset += 6;\n\tattr->type = R_BIN_JAVA_ATTR_TYPE_LINE_NUMBER_TABLE_ATTR;\n\tattr->info.line_number_table_attr.line_number_table_length = R_BIN_JAVA_USHORT (buffer, offset);\n\toffset += 2;\n\tattr->info.line_number_table_attr.line_number_table = r_list_newf (free);", "\tut32 linenum_len = attr->info.line_number_table_attr.line_number_table_length;\n\tRList *linenum_list = attr->info.line_number_table_attr.line_number_table;\n\tif (linenum_len > sz) {\n\t\tfree (attr);\n\t\treturn NULL;\n\t}\n\tfor (i = 0; i < linenum_len; i++) {\n\t\tcurpos = buf_offset + offset;\n\t\t// printf (\"%llx %llx \\n\", curpos, sz);\n\t\t// XXX if (curpos + 8 >= sz) break;\n\t\tlnattr = R_NEW0 (RBinJavaLineNumberAttribute);\n\t\tif (!lnattr) {\n\t\t\tbreak;\n\t\t}", "", "\t\tlnattr->start_pc = R_BIN_JAVA_USHORT (buffer, offset);\n\t\toffset += 2;\n\t\tlnattr->line_number = R_BIN_JAVA_USHORT (buffer, offset);\n\t\toffset += 2;\n\t\tlnattr->file_offset = curpos;\n\t\tlnattr->size = 4;\n\t\tr_list_append (linenum_list, lnattr);\n\t}\n\tattr->size = offset;\n\treturn attr;\n}" ]
[ 1, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1038, "char_start": 998, "chars": "if (offset + 8 >= sz) {\n\t\t\tbreak;\n\t\t}\n\t\t" } ], "deleted": [] }, "commit_link": "github.com/radare/radare2/commit/eb0fb72b3c5307ec8e33effb6bf947e38cfdffe8", "file_name": "shlr/java/class.c", "func_name": "r_bin_java_line_number_table_attr_new", "line_changes": { "added": [ { "char_end": 1022, "char_start": 996, "line": "\t\tif (offset + 8 >= sz) {\n", "line_no": 29 }, { "char_end": 1032, "char_start": 1022, "line": "\t\t\tbreak;\n", "line_no": 30 }, { "char_end": 1036, "char_start": 1032, "line": "\t\t}\n", "line_no": 31 } ], "deleted": [] }, "vul_type": "cwe-125" }
491
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "R_API RBinJavaAttrInfo *r_bin_java_line_number_table_attr_new(ut8 *buffer, ut64 sz, ut64 buf_offset) {\n\tut32 i = 0;\n\tut64 curpos, offset = 0;\n\tRBinJavaLineNumberAttribute *lnattr;\n\tRBinJavaAttrInfo *attr = r_bin_java_default_attr_new (buffer, sz, buf_offset);\n\tif (!attr) {\n\t\treturn NULL;\n\t}\n\toffset += 6;\n\tattr->type = R_BIN_JAVA_ATTR_TYPE_LINE_NUMBER_TABLE_ATTR;\n\tattr->info.line_number_table_attr.line_number_table_length = R_BIN_JAVA_USHORT (buffer, offset);\n\toffset += 2;\n\tattr->info.line_number_table_attr.line_number_table = r_list_newf (free);", "\tut32 linenum_len = attr->info.line_number_table_attr.line_number_table_length;\n\tRList *linenum_list = attr->info.line_number_table_attr.line_number_table;\n\tif (linenum_len > sz) {\n\t\tfree (attr);\n\t\treturn NULL;\n\t}\n\tfor (i = 0; i < linenum_len; i++) {\n\t\tcurpos = buf_offset + offset;\n\t\t// printf (\"%llx %llx \\n\", curpos, sz);\n\t\t// XXX if (curpos + 8 >= sz) break;\n\t\tlnattr = R_NEW0 (RBinJavaLineNumberAttribute);\n\t\tif (!lnattr) {\n\t\t\tbreak;\n\t\t}", "\t\tif (offset + 8 >= sz) {\n\t\t\tbreak;\n\t\t}", "\t\tlnattr->start_pc = R_BIN_JAVA_USHORT (buffer, offset);\n\t\toffset += 2;\n\t\tlnattr->line_number = R_BIN_JAVA_USHORT (buffer, offset);\n\t\toffset += 2;\n\t\tlnattr->file_offset = curpos;\n\t\tlnattr->size = 4;\n\t\tr_list_append (linenum_list, lnattr);\n\t}\n\tattr->size = offset;\n\treturn attr;\n}" ]
[ 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1038, "char_start": 998, "chars": "if (offset + 8 >= sz) {\n\t\t\tbreak;\n\t\t}\n\t\t" } ], "deleted": [] }, "commit_link": "github.com/radare/radare2/commit/eb0fb72b3c5307ec8e33effb6bf947e38cfdffe8", "file_name": "shlr/java/class.c", "func_name": "r_bin_java_line_number_table_attr_new", "line_changes": { "added": [ { "char_end": 1022, "char_start": 996, "line": "\t\tif (offset + 8 >= sz) {\n", "line_no": 29 }, { "char_end": 1032, "char_start": 1022, "line": "\t\t\tbreak;\n", "line_no": 30 }, { "char_end": 1036, "char_start": 1032, "line": "\t\t}\n", "line_no": 31 } ], "deleted": [] }, "vul_type": "cwe-125" }
491
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)\n{\n MpegEncContext *s = &ctx->m;", " if (get_bits_left(gb) <= 32)\n return 0;", " s->partitioned_frame = 0;", "", " s->decode_mb = mpeg4_decode_studio_mb;", " decode_smpte_tc(ctx, gb);", " skip_bits(gb, 10); /* temporal_reference */\n skip_bits(gb, 2); /* vop_structure */\n s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* vop_coding_type */\n if (get_bits1(gb)) { /* vop_coded */\n skip_bits1(gb); /* top_field_first */\n skip_bits1(gb); /* repeat_first_field */\n s->progressive_frame = get_bits1(gb) ^ 1; /* progressive_frame */\n }", " if (s->pict_type == AV_PICTURE_TYPE_I) {\n if (get_bits1(gb))\n reset_studio_dc_predictors(s);\n }", " if (ctx->shape != BIN_ONLY_SHAPE) {\n s->alternate_scan = get_bits1(gb);\n s->frame_pred_frame_dct = get_bits1(gb);\n s->dct_precision = get_bits(gb, 2);\n s->intra_dc_precision = get_bits(gb, 2);\n s->q_scale_type = get_bits1(gb);\n }", " if (s->alternate_scan) {\n ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);\n } else {\n ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);\n }", " mpeg4_load_default_matrices(s);", " next_start_code_studio(gb);\n extension_and_user_data(s, gb, 4);", " return 0;\n}" ]
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 229, "char_start": 202, "chars": "interlaced_dct = 0;\n s->" } ], "deleted": [] }, "commit_link": "github.com/FFmpeg/FFmpeg/commit/1f686d023b95219db933394a7704ad9aa5f01cbb", "file_name": "libavcodec/mpeg4videodec.c", "func_name": "decode_studio_vop_header", "line_changes": { "added": [ { "char_end": 222, "char_start": 195, "line": " s->interlaced_dct = 0;\n", "line_no": 9 } ], "deleted": [] }, "vul_type": "cwe-125" }
492
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)\n{\n MpegEncContext *s = &ctx->m;", " if (get_bits_left(gb) <= 32)\n return 0;", " s->partitioned_frame = 0;", " s->interlaced_dct = 0;", " s->decode_mb = mpeg4_decode_studio_mb;", " decode_smpte_tc(ctx, gb);", " skip_bits(gb, 10); /* temporal_reference */\n skip_bits(gb, 2); /* vop_structure */\n s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* vop_coding_type */\n if (get_bits1(gb)) { /* vop_coded */\n skip_bits1(gb); /* top_field_first */\n skip_bits1(gb); /* repeat_first_field */\n s->progressive_frame = get_bits1(gb) ^ 1; /* progressive_frame */\n }", " if (s->pict_type == AV_PICTURE_TYPE_I) {\n if (get_bits1(gb))\n reset_studio_dc_predictors(s);\n }", " if (ctx->shape != BIN_ONLY_SHAPE) {\n s->alternate_scan = get_bits1(gb);\n s->frame_pred_frame_dct = get_bits1(gb);\n s->dct_precision = get_bits(gb, 2);\n s->intra_dc_precision = get_bits(gb, 2);\n s->q_scale_type = get_bits1(gb);\n }", " if (s->alternate_scan) {\n ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);\n } else {\n ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);\n ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);\n }", " mpeg4_load_default_matrices(s);", " next_start_code_studio(gb);\n extension_and_user_data(s, gb, 4);", " return 0;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 229, "char_start": 202, "chars": "interlaced_dct = 0;\n s->" } ], "deleted": [] }, "commit_link": "github.com/FFmpeg/FFmpeg/commit/1f686d023b95219db933394a7704ad9aa5f01cbb", "file_name": "libavcodec/mpeg4videodec.c", "func_name": "decode_studio_vop_header", "line_changes": { "added": [ { "char_end": 222, "char_start": 195, "line": " s->interlaced_dct = 0;\n", "line_no": 9 } ], "deleted": [] }, "vul_type": "cwe-125" }
492
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "str_lower_case_match(OnigEncoding enc, int case_fold_flag,\n const UChar* t, const UChar* tend,\n const UChar* p, const UChar* end)\n{\n int lowlen;\n UChar *q, lowbuf[ONIGENC_MBC_CASE_FOLD_MAXLEN];", " while (t < tend) {\n lowlen = ONIGENC_MBC_CASE_FOLD(enc, case_fold_flag, &p, end, lowbuf);\n q = lowbuf;\n while (lowlen > 0) {", "", " if (*t++ != *q++) return 0;\n lowlen--;\n }\n }", " return 1;\n}" ]
[ 1, 1, 0, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 417, "char_start": 383, "chars": "t >= tend) return 0;\n if (" } ], "deleted": [] }, "commit_link": "github.com/kkos/oniguruma/commit/d3e402928b6eb3327f8f7d59a9edfa622fec557b", "file_name": "src/regexec.c", "func_name": "str_lower_case_match", "line_changes": { "added": [ { "char_end": 407, "char_start": 373, "line": " if (t >= tend) return 0;\n", "line_no": 12 } ], "deleted": [] }, "vul_type": "cwe-125" }
493
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "str_lower_case_match(OnigEncoding enc, int case_fold_flag,\n const UChar* t, const UChar* tend,\n const UChar* p, const UChar* end)\n{\n int lowlen;\n UChar *q, lowbuf[ONIGENC_MBC_CASE_FOLD_MAXLEN];", " while (t < tend) {\n lowlen = ONIGENC_MBC_CASE_FOLD(enc, case_fold_flag, &p, end, lowbuf);\n q = lowbuf;\n while (lowlen > 0) {", " if (t >= tend) return 0;", " if (*t++ != *q++) return 0;\n lowlen--;\n }\n }", " return 1;\n}" ]
[ 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 417, "char_start": 383, "chars": "t >= tend) return 0;\n if (" } ], "deleted": [] }, "commit_link": "github.com/kkos/oniguruma/commit/d3e402928b6eb3327f8f7d59a9edfa622fec557b", "file_name": "src/regexec.c", "func_name": "str_lower_case_match", "line_changes": { "added": [ { "char_end": 407, "char_start": 373, "line": " if (t >= tend) return 0;\n", "line_no": 12 } ], "deleted": [] }, "vul_type": "cwe-125" }
493
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "bool handleBackslash(signed char& out) {\n char ch = *p++;\n switch (ch) {\n case 0: return false;\n case '\"': out = ch; return true;\n case '\\\\': out = ch; return true;\n case '/': out = ch; return true;\n case 'b': out = '\\b'; return true;\n case 'f': out = '\\f'; return true;\n case 'n': out = '\\n'; return true;\n case 'r': out = '\\r'; return true;\n case 't': out = '\\t'; return true;\n case 'u': {\n if (UNLIKELY(is_tsimplejson)) {\n auto const ch1 = *p++;", "", " auto const ch2 = *p++;", "", " auto const dch3 = dehexchar(*p++);", "", " auto const dch4 = dehexchar(*p++);", " if (UNLIKELY(ch1 != '0' || ch2 != '0' || dch3 < 0 || dch4 < 0)) {\n return false;\n }", " out = (dch3 << 4) | dch4;\n return true;\n } else {\n uint16_t u16cp = 0;\n for (int i = 0; i < 4; i++) {\n auto const hexv = dehexchar(*p++);\n if (hexv < 0) return false; // includes check for end of string\n u16cp <<= 4;\n u16cp |= hexv;\n }\n if (u16cp > 0x7f) {\n return false;\n } else {\n out = u16cp;\n return true;\n }\n }\n }\n default: return false;\n }\n }" ]
[ 1, 0, 1, 0, 1, 0, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 583, "char_start": 533, "chars": "if (UNLIKELY(ch1 != '0')) return false;\n " }, { "char_end": 666, "char_start": 616, "chars": "if (UNLIKELY(ch2 != '0')) return false;\n " }, { "char_end": 759, "char_start": 711, "chars": "if (UNLIKELY(dch3 < 0)) return false;\n " } ], "deleted": [ { "char_end": 709, "char_start": 669, "chars": "ch1 != '0' || ch2 != '0' || dch3 < 0 || " }, { "char_end": 734, "char_start": 720, "chars": "{\n " }, { "char_end": 759, "char_start": 747, "chars": "\n }" } ] }, "commit_link": "github.com/facebook/hhvm/commit/b3679121bb3c7017ff04b4c08402ffff5cf59b13", "file_name": "hphp/runtime/ext/json/JSON_parser.cpp", "func_name": "HPHP::SimpleParser::handleBackslash", "line_changes": { "added": [ { "char_end": 573, "char_start": 523, "line": " if (UNLIKELY(ch1 != '0')) return false;\n", "line_no": 16 }, { "char_end": 656, "char_start": 606, "line": " if (UNLIKELY(ch2 != '0')) return false;\n", "line_no": 18 }, { "char_end": 749, "char_start": 701, "line": " if (UNLIKELY(dch3 < 0)) return false;\n", "line_no": 20 }, { "char_end": 842, "char_start": 794, "line": " if (UNLIKELY(dch4 < 0)) return false;\n", "line_no": 22 } ], "deleted": [ { "char_end": 722, "char_start": 646, "line": " if (UNLIKELY(ch1 != '0' || ch2 != '0' || dch3 < 0 || dch4 < 0)) {\n", "line_no": 19 }, { "char_end": 748, "char_start": 722, "line": " return false;\n", "line_no": 20 }, { "char_end": 760, "char_start": 748, "line": " }\n", "line_no": 21 } ] }, "vul_type": "cwe-125" }
494
cwe-125
cpp
Determine whether the {function_name} code is vulnerable or not.
[ "bool handleBackslash(signed char& out) {\n char ch = *p++;\n switch (ch) {\n case 0: return false;\n case '\"': out = ch; return true;\n case '\\\\': out = ch; return true;\n case '/': out = ch; return true;\n case 'b': out = '\\b'; return true;\n case 'f': out = '\\f'; return true;\n case 'n': out = '\\n'; return true;\n case 'r': out = '\\r'; return true;\n case 't': out = '\\t'; return true;\n case 'u': {\n if (UNLIKELY(is_tsimplejson)) {\n auto const ch1 = *p++;", " if (UNLIKELY(ch1 != '0')) return false;", " auto const ch2 = *p++;", " if (UNLIKELY(ch2 != '0')) return false;", " auto const dch3 = dehexchar(*p++);", " if (UNLIKELY(dch3 < 0)) return false;", " auto const dch4 = dehexchar(*p++);", " if (UNLIKELY(dch4 < 0)) return false;", " out = (dch3 << 4) | dch4;\n return true;\n } else {\n uint16_t u16cp = 0;\n for (int i = 0; i < 4; i++) {\n auto const hexv = dehexchar(*p++);\n if (hexv < 0) return false; // includes check for end of string\n u16cp <<= 4;\n u16cp |= hexv;\n }\n if (u16cp > 0x7f) {\n return false;\n } else {\n out = u16cp;\n return true;\n }\n }\n }\n default: return false;\n }\n }" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 583, "char_start": 533, "chars": "if (UNLIKELY(ch1 != '0')) return false;\n " }, { "char_end": 666, "char_start": 616, "chars": "if (UNLIKELY(ch2 != '0')) return false;\n " }, { "char_end": 759, "char_start": 711, "chars": "if (UNLIKELY(dch3 < 0)) return false;\n " } ], "deleted": [ { "char_end": 709, "char_start": 669, "chars": "ch1 != '0' || ch2 != '0' || dch3 < 0 || " }, { "char_end": 734, "char_start": 720, "chars": "{\n " }, { "char_end": 759, "char_start": 747, "chars": "\n }" } ] }, "commit_link": "github.com/facebook/hhvm/commit/b3679121bb3c7017ff04b4c08402ffff5cf59b13", "file_name": "hphp/runtime/ext/json/JSON_parser.cpp", "func_name": "HPHP::SimpleParser::handleBackslash", "line_changes": { "added": [ { "char_end": 573, "char_start": 523, "line": " if (UNLIKELY(ch1 != '0')) return false;\n", "line_no": 16 }, { "char_end": 656, "char_start": 606, "line": " if (UNLIKELY(ch2 != '0')) return false;\n", "line_no": 18 }, { "char_end": 749, "char_start": 701, "line": " if (UNLIKELY(dch3 < 0)) return false;\n", "line_no": 20 }, { "char_end": 842, "char_start": 794, "line": " if (UNLIKELY(dch4 < 0)) return false;\n", "line_no": 22 } ], "deleted": [ { "char_end": 722, "char_start": 646, "line": " if (UNLIKELY(ch1 != '0' || ch2 != '0' || dch3 < 0 || dch4 < 0)) {\n", "line_no": 19 }, { "char_end": 748, "char_start": 722, "line": " return false;\n", "line_no": 20 }, { "char_end": 760, "char_start": 748, "line": " }\n", "line_no": 21 } ] }, "vul_type": "cwe-125" }
494
cwe-125
cpp
Determine whether the {function_name} code is vulnerable or not.
[ "static OPCODE_DESC* avr_op_analyze(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, CPU_MODEL *cpu) {\n\tOPCODE_DESC *opcode_desc;", "", "\tut16 ins = (buf[1] << 8) | buf[0];\n\tint fail;\n\tchar *t;", "\t// initialize op struct\n\tmemset (op, 0, sizeof (RAnalOp));\n\top->ptr = UT64_MAX;\n\top->val = UT64_MAX;\n\top->jump = UT64_MAX;\n\tr_strbuf_init (&op->esil);", "\t// process opcode\n\tfor (opcode_desc = opcodes; opcode_desc->handler; opcode_desc++) {\n\t\tif ((ins & opcode_desc->mask) == opcode_desc->selector) {\n\t\t\tfail = 0;", "\t\t\t// copy default cycles/size values\n\t\t\top->cycles = opcode_desc->cycles;\n\t\t\top->size = opcode_desc->size;\n\t\t\top->type = opcode_desc->type;\n\t\t\top->jump = UT64_MAX;\n\t\t\top->fail = UT64_MAX;\n\t\t\t// op->fail = addr + op->size;\n\t\t\top->addr = addr;", "\t\t\t// start void esil expression\n\t\t\tr_strbuf_setf (&op->esil, \"\");", "\t\t\t// handle opcode\n\t\t\topcode_desc->handler (anal, op, buf, len, &fail, cpu);\n\t\t\tif (fail) {\n\t\t\t\tgoto INVALID_OP;\n\t\t\t}\n\t\t\tif (op->cycles <= 0) {\n\t\t\t\t// eprintf (\"opcode %s @%\"PFMT64x\" returned 0 cycles.\\n\", opcode_desc->name, op->addr);\n\t\t\t\topcode_desc->cycles = 2;\n\t\t\t}\n\t\t\top->nopcode = (op->type == R_ANAL_OP_TYPE_UNK);", "\t\t\t// remove trailing coma (COMETE LA COMA)\n\t\t\tt = r_strbuf_get (&op->esil);\n\t\t\tif (t && strlen (t) > 1) {\n\t\t\t\tt += strlen (t) - 1;\n\t\t\t\tif (*t == ',') {\n\t\t\t\t\t*t = '\\0';\n\t\t\t\t}\n\t\t\t}", "\t\t\treturn opcode_desc;\n\t\t}\n\t}", "\t// ignore reserved opcodes (if they have not been caught by the previous loop)\n\tif ((ins & 0xff00) == 0xff00 && (ins & 0xf) > 7) {\n\t\tgoto INVALID_OP;\n\t}", "INVALID_OP:\n\t// An unknown or invalid option has appeared.\n\t// -- Throw pokeball!\n\top->family = R_ANAL_OP_FAMILY_UNKNOWN;\n\top->type = R_ANAL_OP_TYPE_UNK;\n\top->addr = addr;\n\top->fail = UT64_MAX;\n\top->jump = UT64_MAX;\n\top->ptr = UT64_MAX;\n\top->val = UT64_MAX;\n\top->nopcode = 1;\n\top->cycles = 1;\n\top->size = 2;\n\t// launch esil trap (for communicating upper layers about this weird\n\t// and stinky situation\n\tr_strbuf_set (&op->esil, \"1,$\");", "\treturn NULL;\n}" ]
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 177, "char_start": 143, "chars": "if (len < 2) {\n\t\treturn NULL;\n\t}\n\t" } ], "deleted": [] }, "commit_link": "github.com/radare/radare2/commit/b35530fa0681b27eba084de5527037ebfb397422", "file_name": "libr/anal/p/anal_avr.c", "func_name": "avr_op_analyze", "line_changes": { "added": [ { "char_end": 158, "char_start": 142, "line": "\tif (len < 2) {\n", "line_no": 3 }, { "char_end": 173, "char_start": 158, "line": "\t\treturn NULL;\n", "line_no": 4 }, { "char_end": 176, "char_start": 173, "line": "\t}\n", "line_no": 5 } ], "deleted": [] }, "vul_type": "cwe-125" }
495
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static OPCODE_DESC* avr_op_analyze(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, CPU_MODEL *cpu) {\n\tOPCODE_DESC *opcode_desc;", "\tif (len < 2) {\n\t\treturn NULL;\n\t}", "\tut16 ins = (buf[1] << 8) | buf[0];\n\tint fail;\n\tchar *t;", "\t// initialize op struct\n\tmemset (op, 0, sizeof (RAnalOp));\n\top->ptr = UT64_MAX;\n\top->val = UT64_MAX;\n\top->jump = UT64_MAX;\n\tr_strbuf_init (&op->esil);", "\t// process opcode\n\tfor (opcode_desc = opcodes; opcode_desc->handler; opcode_desc++) {\n\t\tif ((ins & opcode_desc->mask) == opcode_desc->selector) {\n\t\t\tfail = 0;", "\t\t\t// copy default cycles/size values\n\t\t\top->cycles = opcode_desc->cycles;\n\t\t\top->size = opcode_desc->size;\n\t\t\top->type = opcode_desc->type;\n\t\t\top->jump = UT64_MAX;\n\t\t\top->fail = UT64_MAX;\n\t\t\t// op->fail = addr + op->size;\n\t\t\top->addr = addr;", "\t\t\t// start void esil expression\n\t\t\tr_strbuf_setf (&op->esil, \"\");", "\t\t\t// handle opcode\n\t\t\topcode_desc->handler (anal, op, buf, len, &fail, cpu);\n\t\t\tif (fail) {\n\t\t\t\tgoto INVALID_OP;\n\t\t\t}\n\t\t\tif (op->cycles <= 0) {\n\t\t\t\t// eprintf (\"opcode %s @%\"PFMT64x\" returned 0 cycles.\\n\", opcode_desc->name, op->addr);\n\t\t\t\topcode_desc->cycles = 2;\n\t\t\t}\n\t\t\top->nopcode = (op->type == R_ANAL_OP_TYPE_UNK);", "\t\t\t// remove trailing coma (COMETE LA COMA)\n\t\t\tt = r_strbuf_get (&op->esil);\n\t\t\tif (t && strlen (t) > 1) {\n\t\t\t\tt += strlen (t) - 1;\n\t\t\t\tif (*t == ',') {\n\t\t\t\t\t*t = '\\0';\n\t\t\t\t}\n\t\t\t}", "\t\t\treturn opcode_desc;\n\t\t}\n\t}", "\t// ignore reserved opcodes (if they have not been caught by the previous loop)\n\tif ((ins & 0xff00) == 0xff00 && (ins & 0xf) > 7) {\n\t\tgoto INVALID_OP;\n\t}", "INVALID_OP:\n\t// An unknown or invalid option has appeared.\n\t// -- Throw pokeball!\n\top->family = R_ANAL_OP_FAMILY_UNKNOWN;\n\top->type = R_ANAL_OP_TYPE_UNK;\n\top->addr = addr;\n\top->fail = UT64_MAX;\n\top->jump = UT64_MAX;\n\top->ptr = UT64_MAX;\n\top->val = UT64_MAX;\n\top->nopcode = 1;\n\top->cycles = 1;\n\top->size = 2;\n\t// launch esil trap (for communicating upper layers about this weird\n\t// and stinky situation\n\tr_strbuf_set (&op->esil, \"1,$\");", "\treturn NULL;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 177, "char_start": 143, "chars": "if (len < 2) {\n\t\treturn NULL;\n\t}\n\t" } ], "deleted": [] }, "commit_link": "github.com/radare/radare2/commit/b35530fa0681b27eba084de5527037ebfb397422", "file_name": "libr/anal/p/anal_avr.c", "func_name": "avr_op_analyze", "line_changes": { "added": [ { "char_end": 158, "char_start": 142, "line": "\tif (len < 2) {\n", "line_no": 3 }, { "char_end": 173, "char_start": 158, "line": "\t\treturn NULL;\n", "line_no": 4 }, { "char_end": 176, "char_start": 173, "line": "\t}\n", "line_no": 5 } ], "deleted": [] }, "vul_type": "cwe-125" }
495
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int uas_switch_interface(struct usb_device *udev,\n\t\t\t\tstruct usb_interface *intf)\n{", "\tint alt;", "\n\talt = uas_find_uas_alt_setting(intf);", "\tif (alt < 0)\n\t\treturn alt;", "", "\treturn usb_set_interface(udev,\n\t\t\tintf->altsetting[0].desc.bInterfaceNumber, alt);", "}" ]
[ 1, 0, 1, 0, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 108, "char_start": 92, "chars": "struct usb_host_" }, { "char_end": 117, "char_start": 111, "chars": "erface" }, { "char_end": 119, "char_start": 118, "chars": "*" }, { "char_end": 170, "char_start": 169, "chars": "!" }, { "char_end": 191, "char_start": 184, "chars": "-ENODEV" }, { "char_end": 228, "char_start": 225, "chars": " al" }, { "char_end": 257, "char_start": 253, "chars": "\n\t\t\t" }, { "char_end": 284, "char_start": 260, "chars": "->desc.bAlternateSetting" } ], "deleted": [ { "char_end": 153, "char_start": 149, "chars": " < 0" }, { "char_end": 167, "char_start": 164, "chars": "alt" }, { "char_end": 211, "char_start": 201, "chars": "\n\t\t\tintf->" }, { "char_end": 225, "char_start": 214, "chars": "setting[0]." }, { "char_end": 248, "char_start": 247, "chars": " " } ] }, "commit_link": "github.com/torvalds/linux/commit/786de92b3cb26012d3d0f00ee37adf14527f35c4", "file_name": "drivers/usb/storage/uas.c", "func_name": "uas_switch_interface", "line_changes": { "added": [ { "char_end": 124, "char_start": 91, "line": "\tstruct usb_host_interface *alt;\n", "line_no": 4 }, { "char_end": 175, "char_start": 164, "line": "\tif (!alt)\n", "line_no": 7 }, { "char_end": 193, "char_start": 175, "line": "\t\treturn -ENODEV;\n", "line_no": 8 }, { "char_end": 254, "char_start": 194, "line": "\treturn usb_set_interface(udev, alt->desc.bInterfaceNumber,\n", "line_no": 10 }, { "char_end": 287, "char_start": 254, "line": "\t\t\talt->desc.bAlternateSetting);\n", "line_no": 11 } ], "deleted": [ { "char_end": 101, "char_start": 91, "line": "\tint alt;\n", "line_no": 4 }, { "char_end": 155, "char_start": 141, "line": "\tif (alt < 0)\n", "line_no": 7 }, { "char_end": 169, "char_start": 155, "line": "\t\treturn alt;\n", "line_no": 8 }, { "char_end": 202, "char_start": 170, "line": "\treturn usb_set_interface(udev,\n", "line_no": 10 }, { "char_end": 254, "char_start": 202, "line": "\t\t\tintf->altsetting[0].desc.bInterfaceNumber, alt);\n", "line_no": 11 } ] }, "vul_type": "cwe-125" }
496
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int uas_switch_interface(struct usb_device *udev,\n\t\t\t\tstruct usb_interface *intf)\n{", "\tstruct usb_host_interface *alt;", "\n\talt = uas_find_uas_alt_setting(intf);", "\tif (!alt)\n\t\treturn -ENODEV;", "", "\treturn usb_set_interface(udev, alt->desc.bInterfaceNumber,\n\t\t\talt->desc.bAlternateSetting);", "}" ]
[ 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 108, "char_start": 92, "chars": "struct usb_host_" }, { "char_end": 117, "char_start": 111, "chars": "erface" }, { "char_end": 119, "char_start": 118, "chars": "*" }, { "char_end": 170, "char_start": 169, "chars": "!" }, { "char_end": 191, "char_start": 184, "chars": "-ENODEV" }, { "char_end": 228, "char_start": 225, "chars": " al" }, { "char_end": 257, "char_start": 253, "chars": "\n\t\t\t" }, { "char_end": 284, "char_start": 260, "chars": "->desc.bAlternateSetting" } ], "deleted": [ { "char_end": 153, "char_start": 149, "chars": " < 0" }, { "char_end": 167, "char_start": 164, "chars": "alt" }, { "char_end": 211, "char_start": 201, "chars": "\n\t\t\tintf->" }, { "char_end": 225, "char_start": 214, "chars": "setting[0]." }, { "char_end": 248, "char_start": 247, "chars": " " } ] }, "commit_link": "github.com/torvalds/linux/commit/786de92b3cb26012d3d0f00ee37adf14527f35c4", "file_name": "drivers/usb/storage/uas.c", "func_name": "uas_switch_interface", "line_changes": { "added": [ { "char_end": 124, "char_start": 91, "line": "\tstruct usb_host_interface *alt;\n", "line_no": 4 }, { "char_end": 175, "char_start": 164, "line": "\tif (!alt)\n", "line_no": 7 }, { "char_end": 193, "char_start": 175, "line": "\t\treturn -ENODEV;\n", "line_no": 8 }, { "char_end": 254, "char_start": 194, "line": "\treturn usb_set_interface(udev, alt->desc.bInterfaceNumber,\n", "line_no": 10 }, { "char_end": 287, "char_start": 254, "line": "\t\t\talt->desc.bAlternateSetting);\n", "line_no": 11 } ], "deleted": [ { "char_end": 101, "char_start": 91, "line": "\tint alt;\n", "line_no": 4 }, { "char_end": 155, "char_start": 141, "line": "\tif (alt < 0)\n", "line_no": 7 }, { "char_end": 169, "char_start": 155, "line": "\t\treturn alt;\n", "line_no": 8 }, { "char_end": 202, "char_start": 170, "line": "\treturn usb_set_interface(udev,\n", "line_no": 10 }, { "char_end": 254, "char_start": 202, "line": "\t\t\tintf->altsetting[0].desc.bInterfaceNumber, alt);\n", "line_no": 11 } ] }, "vul_type": "cwe-125" }
496
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int sh_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {\n\tut8 op_MSB,op_LSB;\n\tint ret;", "\tif (!data)", "\t\treturn 0;", "", "\tmemset (op, '\\0', sizeof (RAnalOp));\n\top->addr = addr;\n\top->type = R_ANAL_OP_TYPE_UNK;\n\top->jump = op->fail = -1;\n\top->ptr = op->val = -1;", "\top->size = 2;", "\top_MSB = anal->big_endian? data[0]: data[1];\n\top_LSB = anal->big_endian? data[1]: data[0];\n\tret = first_nibble_decode[(op_MSB>>4) & 0x0F](anal, op, (ut16)(op_MSB<<8 | op_LSB));\n\treturn ret;\n}" ]
[ 1, 0, 1, 0, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 133, "char_start": 122, "chars": " || len < 2" }, { "char_end": 136, "char_start": 134, "chars": " {" }, { "char_end": 151, "char_start": 148, "chars": "\n\t}" } ], "deleted": [] }, "commit_link": "github.com/radare/radare2/commit/77c47cf873dd55b396da60baa2ca83bbd39e4add", "file_name": "libr/anal/p/anal_sh.c", "func_name": "sh_op", "line_changes": { "added": [ { "char_end": 137, "char_start": 112, "line": "\tif (!data || len < 2) {\n", "line_no": 4 }, { "char_end": 152, "char_start": 149, "line": "\t}\n", "line_no": 6 } ], "deleted": [ { "char_end": 124, "char_start": 112, "line": "\tif (!data)\n", "line_no": 4 } ] }, "vul_type": "cwe-125" }
497
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int sh_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {\n\tut8 op_MSB,op_LSB;\n\tint ret;", "\tif (!data || len < 2) {", "\t\treturn 0;", "\t}", "\tmemset (op, '\\0', sizeof (RAnalOp));\n\top->addr = addr;\n\top->type = R_ANAL_OP_TYPE_UNK;\n\top->jump = op->fail = -1;\n\top->ptr = op->val = -1;", "\top->size = 2;", "\top_MSB = anal->big_endian? data[0]: data[1];\n\top_LSB = anal->big_endian? data[1]: data[0];\n\tret = first_nibble_decode[(op_MSB>>4) & 0x0F](anal, op, (ut16)(op_MSB<<8 | op_LSB));\n\treturn ret;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 133, "char_start": 122, "chars": " || len < 2" }, { "char_end": 136, "char_start": 134, "chars": " {" }, { "char_end": 151, "char_start": 148, "chars": "\n\t}" } ], "deleted": [] }, "commit_link": "github.com/radare/radare2/commit/77c47cf873dd55b396da60baa2ca83bbd39e4add", "file_name": "libr/anal/p/anal_sh.c", "func_name": "sh_op", "line_changes": { "added": [ { "char_end": 137, "char_start": 112, "line": "\tif (!data || len < 2) {\n", "line_no": 4 }, { "char_end": 152, "char_start": 149, "line": "\t}\n", "line_no": 6 } ], "deleted": [ { "char_end": 124, "char_start": 112, "line": "\tif (!data)\n", "line_no": 4 } ] }, "vul_type": "cwe-125" }
497
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static MagickBooleanType ReadPSDChannelPixels(Image *image,\n const size_t channels,const size_t row,const ssize_t type,\n const unsigned char *pixels,ExceptionInfo *exception)\n{\n Quantum\n pixel;", " register const unsigned char\n *p;", " register Quantum\n *q;", " register ssize_t\n x;", " size_t\n packet_size;", " unsigned short\n nibble;", " p=pixels;\n q=GetAuthenticPixels(image,0,row,image->columns,1,exception);\n if (q == (Quantum *) NULL)\n return MagickFalse;\n packet_size=GetPSDPacketSize(image);\n for (x=0; x < (ssize_t) image->columns; x++)\n {\n if (packet_size == 1)\n pixel=ScaleCharToQuantum(*p++);\n else\n {\n p=PushShortPixel(MSBEndian,p,&nibble);\n pixel=ScaleShortToQuantum(nibble);\n }\n switch (type)\n {\n case -1:\n {\n SetPixelAlpha(image,pixel,q);\n break;\n }\n case -2:\n case 0:\n {\n SetPixelRed(image,pixel,q);\n if (channels == 1 || type == -2)\n SetPixelGray(image,pixel,q);\n if (image->storage_class == PseudoClass)\n {\n if (packet_size == 1)\n SetPixelIndex(image,ScaleQuantumToChar(pixel),q);\n else\n SetPixelIndex(image,ScaleQuantumToShort(pixel),q);\n SetPixelViaPixelInfo(image,image->colormap+(ssize_t)\n ConstrainColormapIndex(image,GetPixelIndex(image,q),exception),q);\n if (image->depth == 1)\n {\n ssize_t\n bit,\n number_bits;\n \n number_bits=image->columns-x;\n if (number_bits > 8)\n number_bits=8;\n for (bit=0; bit < number_bits; bit++)\n {\n SetPixelIndex(image,(((unsigned char) pixel) &\n (0x01 << (7-bit))) != 0 ? 0 : 255,q);\n SetPixelViaPixelInfo(image,image->colormap+(ssize_t)", " GetPixelIndex(image,q),q);", " q+=GetPixelChannels(image);\n x++;\n }\n x--;\n continue;\n }\n }\n break;\n }\n case 1:\n {\n if (image->storage_class == PseudoClass)\n SetPixelAlpha(image,pixel,q);\n else\n SetPixelGreen(image,pixel,q);\n break;\n }\n case 2:\n {\n if (image->storage_class == PseudoClass)\n SetPixelAlpha(image,pixel,q);\n else\n SetPixelBlue(image,pixel,q);\n break;\n }\n case 3:\n {\n if (image->colorspace == CMYKColorspace)\n SetPixelBlack(image,pixel,q);\n else\n if (image->alpha_trait != UndefinedPixelTrait)\n SetPixelAlpha(image,pixel,q);\n break;\n }\n case 4:\n {\n if ((IssRGBCompatibleColorspace(image->colorspace) != MagickFalse) &&\n (channels > 3))\n break;\n if (image->alpha_trait != UndefinedPixelTrait)\n SetPixelAlpha(image,pixel,q);\n break;\n }\n default:\n break;\n }\n q+=GetPixelChannels(image);\n }\n return(SyncAuthenticPixels(image,exception));\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1962, "char_start": 1933, "chars": "ConstrainColormapIndex(image," }, { "char_end": 2017, "char_start": 1983, "chars": "),\n exception" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/e14fd0a2801f73bdc123baf4fbab97dec55919eb", "file_name": "coders/psd.c", "func_name": "ReadPSDChannelPixels", "line_changes": { "added": [ { "char_end": 1986, "char_start": 1913, "line": " ConstrainColormapIndex(image,GetPixelIndex(image,q),\n", "line_no": 72 }, { "char_end": 2023, "char_start": 1986, "line": " exception),q);\n", "line_no": 73 } ], "deleted": [ { "char_end": 1960, "char_start": 1913, "line": " GetPixelIndex(image,q),q);\n", "line_no": 72 } ] }, "vul_type": "cwe-125" }
498
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static MagickBooleanType ReadPSDChannelPixels(Image *image,\n const size_t channels,const size_t row,const ssize_t type,\n const unsigned char *pixels,ExceptionInfo *exception)\n{\n Quantum\n pixel;", " register const unsigned char\n *p;", " register Quantum\n *q;", " register ssize_t\n x;", " size_t\n packet_size;", " unsigned short\n nibble;", " p=pixels;\n q=GetAuthenticPixels(image,0,row,image->columns,1,exception);\n if (q == (Quantum *) NULL)\n return MagickFalse;\n packet_size=GetPSDPacketSize(image);\n for (x=0; x < (ssize_t) image->columns; x++)\n {\n if (packet_size == 1)\n pixel=ScaleCharToQuantum(*p++);\n else\n {\n p=PushShortPixel(MSBEndian,p,&nibble);\n pixel=ScaleShortToQuantum(nibble);\n }\n switch (type)\n {\n case -1:\n {\n SetPixelAlpha(image,pixel,q);\n break;\n }\n case -2:\n case 0:\n {\n SetPixelRed(image,pixel,q);\n if (channels == 1 || type == -2)\n SetPixelGray(image,pixel,q);\n if (image->storage_class == PseudoClass)\n {\n if (packet_size == 1)\n SetPixelIndex(image,ScaleQuantumToChar(pixel),q);\n else\n SetPixelIndex(image,ScaleQuantumToShort(pixel),q);\n SetPixelViaPixelInfo(image,image->colormap+(ssize_t)\n ConstrainColormapIndex(image,GetPixelIndex(image,q),exception),q);\n if (image->depth == 1)\n {\n ssize_t\n bit,\n number_bits;\n \n number_bits=image->columns-x;\n if (number_bits > 8)\n number_bits=8;\n for (bit=0; bit < number_bits; bit++)\n {\n SetPixelIndex(image,(((unsigned char) pixel) &\n (0x01 << (7-bit))) != 0 ? 0 : 255,q);\n SetPixelViaPixelInfo(image,image->colormap+(ssize_t)", " ConstrainColormapIndex(image,GetPixelIndex(image,q),\n exception),q);", " q+=GetPixelChannels(image);\n x++;\n }\n x--;\n continue;\n }\n }\n break;\n }\n case 1:\n {\n if (image->storage_class == PseudoClass)\n SetPixelAlpha(image,pixel,q);\n else\n SetPixelGreen(image,pixel,q);\n break;\n }\n case 2:\n {\n if (image->storage_class == PseudoClass)\n SetPixelAlpha(image,pixel,q);\n else\n SetPixelBlue(image,pixel,q);\n break;\n }\n case 3:\n {\n if (image->colorspace == CMYKColorspace)\n SetPixelBlack(image,pixel,q);\n else\n if (image->alpha_trait != UndefinedPixelTrait)\n SetPixelAlpha(image,pixel,q);\n break;\n }\n case 4:\n {\n if ((IssRGBCompatibleColorspace(image->colorspace) != MagickFalse) &&\n (channels > 3))\n break;\n if (image->alpha_trait != UndefinedPixelTrait)\n SetPixelAlpha(image,pixel,q);\n break;\n }\n default:\n break;\n }\n q+=GetPixelChannels(image);\n }\n return(SyncAuthenticPixels(image,exception));\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 1962, "char_start": 1933, "chars": "ConstrainColormapIndex(image," }, { "char_end": 2017, "char_start": 1983, "chars": "),\n exception" } ], "deleted": [] }, "commit_link": "github.com/ImageMagick/ImageMagick/commit/e14fd0a2801f73bdc123baf4fbab97dec55919eb", "file_name": "coders/psd.c", "func_name": "ReadPSDChannelPixels", "line_changes": { "added": [ { "char_end": 1986, "char_start": 1913, "line": " ConstrainColormapIndex(image,GetPixelIndex(image,q),\n", "line_no": 72 }, { "char_end": 2023, "char_start": 1986, "line": " exception),q);\n", "line_no": 73 } ], "deleted": [ { "char_end": 1960, "char_start": 1913, "line": " GetPixelIndex(image,q),q);\n", "line_no": 72 } ] }, "vul_type": "cwe-125" }
498
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int ape_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame_ptr, AVPacket *avpkt)\n{\n AVFrame *frame = data;\n const uint8_t *buf = avpkt->data;\n APEContext *s = avctx->priv_data;\n uint8_t *sample8;\n int16_t *sample16;\n int32_t *sample24;\n int i, ch, ret;\n int blockstodecode;", "", "\n /* this should never be negative, but bad things will happen if it is, so\n check it just to make sure. */\n av_assert0(s->samples >= 0);", " if(!s->samples){\n uint32_t nblocks, offset;\n int buf_size;", " if (!avpkt->size) {\n *got_frame_ptr = 0;\n return 0;\n }\n if (avpkt->size < 8) {\n av_log(avctx, AV_LOG_ERROR, \"Packet is too small\\n\");\n return AVERROR_INVALIDDATA;\n }\n buf_size = avpkt->size & ~3;\n if (buf_size != avpkt->size) {\n av_log(avctx, AV_LOG_WARNING, \"packet size is not a multiple of 4. \"\n \"extra bytes at the end will be skipped.\\n\");\n }\n if (s->fileversion < 3950) // previous versions overread two bytes\n buf_size += 2;\n av_fast_padded_malloc(&s->data, &s->data_size, buf_size);\n if (!s->data)\n return AVERROR(ENOMEM);\n s->bdsp.bswap_buf((uint32_t *) s->data, (const uint32_t *) buf,\n buf_size >> 2);\n memset(s->data + (buf_size & ~3), 0, buf_size & 3);\n s->ptr = s->data;\n s->data_end = s->data + buf_size;", " nblocks = bytestream_get_be32(&s->ptr);\n offset = bytestream_get_be32(&s->ptr);\n if (s->fileversion >= 3900) {\n if (offset > 3) {\n av_log(avctx, AV_LOG_ERROR, \"Incorrect offset passed\\n\");\n s->data = NULL;\n return AVERROR_INVALIDDATA;\n }\n if (s->data_end - s->ptr < offset) {\n av_log(avctx, AV_LOG_ERROR, \"Packet is too small\\n\");\n return AVERROR_INVALIDDATA;\n }\n s->ptr += offset;\n } else {\n if ((ret = init_get_bits8(&s->gb, s->ptr, s->data_end - s->ptr)) < 0)\n return ret;\n if (s->fileversion > 3800)\n skip_bits_long(&s->gb, offset * 8);\n else\n skip_bits_long(&s->gb, offset);\n }\n", " if (!nblocks || nblocks > INT_MAX) {", " av_log(avctx, AV_LOG_ERROR, \"Invalid sample count: %\"PRIu32\".\\n\",\n nblocks);\n return AVERROR_INVALIDDATA;\n }", " /* Initialize the frame decoder */\n if (init_frame_decoder(s) < 0) {\n av_log(avctx, AV_LOG_ERROR, \"Error reading frame header\\n\");\n return AVERROR_INVALIDDATA;\n }\n s->samples = nblocks;\n }", " if (!s->data) {\n *got_frame_ptr = 0;\n return avpkt->size;\n }", " blockstodecode = FFMIN(s->blocks_per_loop, s->samples);\n // for old files coefficients were not interleaved,\n // so we need to decode all of them at once\n if (s->fileversion < 3930)\n blockstodecode = s->samples;", " /* reallocate decoded sample buffer if needed */", " av_fast_malloc(&s->decoded_buffer, &s->decoded_size,\n 2 * FFALIGN(blockstodecode, 8) * sizeof(*s->decoded_buffer));", " if (!s->decoded_buffer)\n return AVERROR(ENOMEM);\n memset(s->decoded_buffer, 0, s->decoded_size);\n s->decoded[0] = s->decoded_buffer;\n s->decoded[1] = s->decoded_buffer + FFALIGN(blockstodecode, 8);", " /* get output buffer */\n frame->nb_samples = blockstodecode;\n if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)\n return ret;", " s->error=0;", " if ((s->channels == 1) || (s->frameflags & APE_FRAMECODE_PSEUDO_STEREO))\n ape_unpack_mono(s, blockstodecode);\n else\n ape_unpack_stereo(s, blockstodecode);\n emms_c();", " if (s->error) {\n s->samples=0;\n av_log(avctx, AV_LOG_ERROR, \"Error decoding frame\\n\");\n return AVERROR_INVALIDDATA;\n }", " switch (s->bps) {\n case 8:\n for (ch = 0; ch < s->channels; ch++) {\n sample8 = (uint8_t *)frame->data[ch];\n for (i = 0; i < blockstodecode; i++)\n *sample8++ = (s->decoded[ch][i] + 0x80) & 0xff;\n }\n break;\n case 16:\n for (ch = 0; ch < s->channels; ch++) {\n sample16 = (int16_t *)frame->data[ch];\n for (i = 0; i < blockstodecode; i++)\n *sample16++ = s->decoded[ch][i];\n }\n break;\n case 24:\n for (ch = 0; ch < s->channels; ch++) {\n sample24 = (int32_t *)frame->data[ch];\n for (i = 0; i < blockstodecode; i++)\n *sample24++ = s->decoded[ch][i] << 8;\n }\n break;\n }", " s->samples -= blockstodecode;", " *got_frame_ptr = 1;", " return !s->samples ? avpkt->size : 0;\n}" ]
[ 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 383, "char_start": 349, "chars": " uint64_t decoded_buffer_size;\n" }, { "char_end": 2459, "char_start": 2422, "chars": " / 2 / sizeof(*s->decoded_buffer) - 8" }, { "char_end": 3259, "char_start": 3258, "chars": "=" }, { "char_end": 3263, "char_start": 3261, "chars": "LL" }, { "char_end": 3447, "char_start": 3321, "chars": ";\n av_assert0(decoded_buffer_size <= INT_MAX);\n av_fast_malloc(&s->decoded_buffer, &s->decoded_size, decoded_buffer_size" } ], "deleted": [ { "char_end": 3186, "char_start": 3167, "chars": "av_fast_malloc(&s->" }, { "char_end": 3213, "char_start": 3200, "chars": ", &s->decoded" }, { "char_end": 3231, "char_start": 3218, "chars": ",\n " }, { "char_end": 3238, "char_start": 3232, "chars": " " } ] }, "commit_link": "github.com/FFmpeg/FFmpeg/commit/ba4beaf6149f7241c8bd85fe853318c2f6837ad0", "file_name": "libavcodec/apedec.c", "func_name": "ape_decode_frame", "line_changes": { "added": [ { "char_end": 383, "char_start": 349, "line": " uint64_t decoded_buffer_size;\n", "line_no": 12 }, { "char_end": 2463, "char_start": 2381, "line": " if (!nblocks || nblocks > INT_MAX / 2 / sizeof(*s->decoded_buffer) - 8) {\n", "line_no": 68 }, { "char_end": 3323, "char_start": 3234, "line": " decoded_buffer_size = 2LL * FFALIGN(blockstodecode, 8) * sizeof(*s->decoded_buffer);\n", "line_no": 94 }, { "char_end": 3371, "char_start": 3323, "line": " av_assert0(decoded_buffer_size <= INT_MAX);\n", "line_no": 95 }, { "char_end": 3450, "char_start": 3371, "line": " av_fast_malloc(&s->decoded_buffer, &s->decoded_size, decoded_buffer_size);\n", "line_no": 96 } ], "deleted": [ { "char_end": 2392, "char_start": 2347, "line": " if (!nblocks || nblocks > INT_MAX) {\n", "line_no": 67 }, { "char_end": 3220, "char_start": 3163, "line": " av_fast_malloc(&s->decoded_buffer, &s->decoded_size,\n", "line_no": 93 }, { "char_end": 3301, "char_start": 3220, "line": " 2 * FFALIGN(blockstodecode, 8) * sizeof(*s->decoded_buffer));\n", "line_no": 94 } ] }, "vul_type": "cwe-125" }
499
cwe-125
c
Determine whether the {function_name} code is vulnerable or not.
[ "static int ape_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame_ptr, AVPacket *avpkt)\n{\n AVFrame *frame = data;\n const uint8_t *buf = avpkt->data;\n APEContext *s = avctx->priv_data;\n uint8_t *sample8;\n int16_t *sample16;\n int32_t *sample24;\n int i, ch, ret;\n int blockstodecode;", " uint64_t decoded_buffer_size;", "\n /* this should never be negative, but bad things will happen if it is, so\n check it just to make sure. */\n av_assert0(s->samples >= 0);", " if(!s->samples){\n uint32_t nblocks, offset;\n int buf_size;", " if (!avpkt->size) {\n *got_frame_ptr = 0;\n return 0;\n }\n if (avpkt->size < 8) {\n av_log(avctx, AV_LOG_ERROR, \"Packet is too small\\n\");\n return AVERROR_INVALIDDATA;\n }\n buf_size = avpkt->size & ~3;\n if (buf_size != avpkt->size) {\n av_log(avctx, AV_LOG_WARNING, \"packet size is not a multiple of 4. \"\n \"extra bytes at the end will be skipped.\\n\");\n }\n if (s->fileversion < 3950) // previous versions overread two bytes\n buf_size += 2;\n av_fast_padded_malloc(&s->data, &s->data_size, buf_size);\n if (!s->data)\n return AVERROR(ENOMEM);\n s->bdsp.bswap_buf((uint32_t *) s->data, (const uint32_t *) buf,\n buf_size >> 2);\n memset(s->data + (buf_size & ~3), 0, buf_size & 3);\n s->ptr = s->data;\n s->data_end = s->data + buf_size;", " nblocks = bytestream_get_be32(&s->ptr);\n offset = bytestream_get_be32(&s->ptr);\n if (s->fileversion >= 3900) {\n if (offset > 3) {\n av_log(avctx, AV_LOG_ERROR, \"Incorrect offset passed\\n\");\n s->data = NULL;\n return AVERROR_INVALIDDATA;\n }\n if (s->data_end - s->ptr < offset) {\n av_log(avctx, AV_LOG_ERROR, \"Packet is too small\\n\");\n return AVERROR_INVALIDDATA;\n }\n s->ptr += offset;\n } else {\n if ((ret = init_get_bits8(&s->gb, s->ptr, s->data_end - s->ptr)) < 0)\n return ret;\n if (s->fileversion > 3800)\n skip_bits_long(&s->gb, offset * 8);\n else\n skip_bits_long(&s->gb, offset);\n }\n", " if (!nblocks || nblocks > INT_MAX / 2 / sizeof(*s->decoded_buffer) - 8) {", " av_log(avctx, AV_LOG_ERROR, \"Invalid sample count: %\"PRIu32\".\\n\",\n nblocks);\n return AVERROR_INVALIDDATA;\n }", " /* Initialize the frame decoder */\n if (init_frame_decoder(s) < 0) {\n av_log(avctx, AV_LOG_ERROR, \"Error reading frame header\\n\");\n return AVERROR_INVALIDDATA;\n }\n s->samples = nblocks;\n }", " if (!s->data) {\n *got_frame_ptr = 0;\n return avpkt->size;\n }", " blockstodecode = FFMIN(s->blocks_per_loop, s->samples);\n // for old files coefficients were not interleaved,\n // so we need to decode all of them at once\n if (s->fileversion < 3930)\n blockstodecode = s->samples;", " /* reallocate decoded sample buffer if needed */", " decoded_buffer_size = 2LL * FFALIGN(blockstodecode, 8) * sizeof(*s->decoded_buffer);\n av_assert0(decoded_buffer_size <= INT_MAX);\n av_fast_malloc(&s->decoded_buffer, &s->decoded_size, decoded_buffer_size);", " if (!s->decoded_buffer)\n return AVERROR(ENOMEM);\n memset(s->decoded_buffer, 0, s->decoded_size);\n s->decoded[0] = s->decoded_buffer;\n s->decoded[1] = s->decoded_buffer + FFALIGN(blockstodecode, 8);", " /* get output buffer */\n frame->nb_samples = blockstodecode;\n if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)\n return ret;", " s->error=0;", " if ((s->channels == 1) || (s->frameflags & APE_FRAMECODE_PSEUDO_STEREO))\n ape_unpack_mono(s, blockstodecode);\n else\n ape_unpack_stereo(s, blockstodecode);\n emms_c();", " if (s->error) {\n s->samples=0;\n av_log(avctx, AV_LOG_ERROR, \"Error decoding frame\\n\");\n return AVERROR_INVALIDDATA;\n }", " switch (s->bps) {\n case 8:\n for (ch = 0; ch < s->channels; ch++) {\n sample8 = (uint8_t *)frame->data[ch];\n for (i = 0; i < blockstodecode; i++)\n *sample8++ = (s->decoded[ch][i] + 0x80) & 0xff;\n }\n break;\n case 16:\n for (ch = 0; ch < s->channels; ch++) {\n sample16 = (int16_t *)frame->data[ch];\n for (i = 0; i < blockstodecode; i++)\n *sample16++ = s->decoded[ch][i];\n }\n break;\n case 24:\n for (ch = 0; ch < s->channels; ch++) {\n sample24 = (int32_t *)frame->data[ch];\n for (i = 0; i < blockstodecode; i++)\n *sample24++ = s->decoded[ch][i] << 8;\n }\n break;\n }", " s->samples -= blockstodecode;", " *got_frame_ptr = 1;", " return !s->samples ? avpkt->size : 0;\n}" ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SVEN
{ "char_changes": { "added": [ { "char_end": 383, "char_start": 349, "chars": " uint64_t decoded_buffer_size;\n" }, { "char_end": 2459, "char_start": 2422, "chars": " / 2 / sizeof(*s->decoded_buffer) - 8" }, { "char_end": 3259, "char_start": 3258, "chars": "=" }, { "char_end": 3263, "char_start": 3261, "chars": "LL" }, { "char_end": 3447, "char_start": 3321, "chars": ";\n av_assert0(decoded_buffer_size <= INT_MAX);\n av_fast_malloc(&s->decoded_buffer, &s->decoded_size, decoded_buffer_size" } ], "deleted": [ { "char_end": 3186, "char_start": 3167, "chars": "av_fast_malloc(&s->" }, { "char_end": 3213, "char_start": 3200, "chars": ", &s->decoded" }, { "char_end": 3231, "char_start": 3218, "chars": ",\n " }, { "char_end": 3238, "char_start": 3232, "chars": " " } ] }, "commit_link": "github.com/FFmpeg/FFmpeg/commit/ba4beaf6149f7241c8bd85fe853318c2f6837ad0", "file_name": "libavcodec/apedec.c", "func_name": "ape_decode_frame", "line_changes": { "added": [ { "char_end": 383, "char_start": 349, "line": " uint64_t decoded_buffer_size;\n", "line_no": 12 }, { "char_end": 2463, "char_start": 2381, "line": " if (!nblocks || nblocks > INT_MAX / 2 / sizeof(*s->decoded_buffer) - 8) {\n", "line_no": 68 }, { "char_end": 3323, "char_start": 3234, "line": " decoded_buffer_size = 2LL * FFALIGN(blockstodecode, 8) * sizeof(*s->decoded_buffer);\n", "line_no": 94 }, { "char_end": 3371, "char_start": 3323, "line": " av_assert0(decoded_buffer_size <= INT_MAX);\n", "line_no": 95 }, { "char_end": 3450, "char_start": 3371, "line": " av_fast_malloc(&s->decoded_buffer, &s->decoded_size, decoded_buffer_size);\n", "line_no": 96 } ], "deleted": [ { "char_end": 2392, "char_start": 2347, "line": " if (!nblocks || nblocks > INT_MAX) {\n", "line_no": 67 }, { "char_end": 3220, "char_start": 3163, "line": " av_fast_malloc(&s->decoded_buffer, &s->decoded_size,\n", "line_no": 93 }, { "char_end": 3301, "char_start": 3220, "line": " 2 * FFALIGN(blockstodecode, 8) * sizeof(*s->decoded_buffer));\n", "line_no": 94 } ] }, "vul_type": "cwe-125" }
499
cwe-125
c