Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge case errors in multipart binary file uploads #18

Open
shaunkime opened this issue May 8, 2014 · 0 comments
Open

Edge case errors in multipart binary file uploads #18

shaunkime opened this issue May 8, 2014 · 0 comments

Comments

@shaunkime
Copy link

I found this error in the lacewing version of the multipart-parser-c, but I think that it also resides in your original version.

When in the s_part_data_almost_boundary condition when dealing with the test for a LF character fails, there are two current bad edge conditions, when i is 0 or when i is_last. Additionally, in the s_part_data_boundary condition when the boundary does not equal the current index, there is an edge condition when i is_last as well.

Cutting & pasting my local changes with debugging logic still in place:

multipart_parser.c(228)
/* fallthrough */
case s_part_data:
multipart_log("s_part_data");
if (c == CR) {
EMIT_DATA_CB(part_data, buf + mark, i - mark);
mark = i;
p->state = s_part_data_almost_boundary;
p->lookbehind[0] = CR;
break;
}
if (is_last)
EMIT_DATA_CB(part_data, buf + mark, (i - mark) + 1);
break;

case s_part_data_almost_boundary:
multipart_log("s_part_data_almost_boundary");
if (c == LF) {
p->state = s_part_data_boundary;
p->lookbehind[1] = LF;
p->index = 0;
break;
}
EMIT_DATA_CB(part_data, p->lookbehind, 1);
p->state = s_part_data;

//  sckime edit  begin
if (i == 0)
{
  mark = i; // The new buffer mark is the start, would otherwise be -1
}
else if (is_last)
{
  mark = i; 
  EMIT_DATA_CB(part_data, buf + mark, (i - mark) + 1); // No one will output this data otherwise.
}
else
//  sckime edit  end
{
  mark = i --;
}
break;

case s_part_data_boundary:
multipart_log("s_part_data_boundary");
if (p->multipart_boundary[p->index] != c) {
EMIT_DATA_CB(part_data, p->lookbehind, 2 + p->index);
p->state = s_part_data;
mark = i --;

  // sckime edit begin
  if (is_last)
  {
    mark = i;
    EMIT_DATA_CB(part_data, buf + mark, (i - mark) + 1);  // No one will output this data otherwise.
  }
  //sckime edit end
  break;
}
p->lookbehind[2 + p->index] = c;
if ((++ p->index) == p->boundary_length) {
    NOTIFY_CB(part_data_end);
    p->state = s_part_data_almost_end;
}
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant