Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/multipartparser/AphrontMultipartParser.php
Context not available. | |||||
throw new PhutilInvalidStateException('setContentType'); | throw new PhutilInvalidStateException('setContentType'); | ||||
} | } | ||||
if (!preg_match('(^multipart/form-data)', $content_type)) { | if (!@preg_match('(^multipart/form-data)', $content_type)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Expected "multipart/form-data" content type when executing a '. | 'Expected "multipart/form-data" content type when executing a '. | ||||
Context not available. | |||||
$boundary = null; | $boundary = null; | ||||
foreach ($type_parts as $type_part) { | foreach ($type_parts as $type_part) { | ||||
$matches = null; | $matches = null; | ||||
if (preg_match('(^boundary=(.*))', $type_part, $matches)) { | if (@preg_match('(^boundary=(.*))', $type_part, $matches)) { | ||||
$boundary = $matches[1]; | $boundary = $matches[1]; | ||||
break; | break; | ||||
} | } | ||||
Context not available. | |||||
// indicates we've reached the end of the parts) or "\r\n" (which | // indicates we've reached the end of the parts) or "\r\n" (which | ||||
// indicates we should read the headers for the next part). | // indicates we should read the headers for the next part). | ||||
if (strlen($this->buffer) < 2) { | if (@strlen($this->buffer) < 2) { | ||||
// We don't have enough bytes yet, so wait for more. | // We don't have enough bytes yet, so wait for more. | ||||
$continue = false; | $continue = false; | ||||
break; | break; | ||||
Context not available. | |||||
if (!strncmp($this->buffer, '--', 2)) { | if (!strncmp($this->buffer, '--', 2)) { | ||||
// This is "--" after a boundary, so we're done. We'll read the | // This is "--" after a boundary, so we're done. We'll read the | ||||
// rest of the body (the "epilogue") and discard it. | // rest of the body (the "epilogue") and discard it. | ||||
$this->buffer = substr($this->buffer, 2); | $this->buffer = @substr($this->buffer, 2); | ||||
$this->state = 'epilogue'; | $this->state = 'epilogue'; | ||||
$this->part = null; | $this->part = null; | ||||
Context not available. | |||||
if (!strncmp($this->buffer, "\r\n", 2)) { | if (!strncmp($this->buffer, "\r\n", 2)) { | ||||
// This is "\r\n" after a boundary, so we're going to going to | // This is "\r\n" after a boundary, so we're going to going to | ||||
// read the headers for a part. | // read the headers for a part. | ||||
$this->buffer = substr($this->buffer, 2); | $this->buffer = @substr($this->buffer, 2); | ||||
$this->state = 'header'; | $this->state = 'header'; | ||||
// Create the object to hold the part we're about to read. | // Create the object to hold the part we're about to read. | ||||
Context not available. | |||||
// headers and terminated by "\r\n". The section is terminated by | // headers and terminated by "\r\n". The section is terminated by | ||||
// a line with no header on it. | // a line with no header on it. | ||||
if (strlen($this->buffer) < 2) { | if (@strlen($this->buffer) < 2) { | ||||
// We don't have enough data to find a "\r\n", so wait for more. | // We don't have enough data to find a "\r\n", so wait for more. | ||||
$continue = false; | $continue = false; | ||||
break; | break; | ||||
Context not available. | |||||
if (!strncmp("\r\n", $this->buffer, 2)) { | if (!strncmp("\r\n", $this->buffer, 2)) { | ||||
// This line immediately began "\r\n", so we're done with parsing | // This line immediately began "\r\n", so we're done with parsing | ||||
// headers. Start parsing the body. | // headers. Start parsing the body. | ||||
$this->buffer = substr($this->buffer, 2); | $this->buffer = @substr($this->buffer, 2); | ||||
$this->state = 'body'; | $this->state = 'body'; | ||||
break; | break; | ||||
} | } | ||||
// This is an actual header, so look for the end of it. | // This is an actual header, so look for the end of it. | ||||
$header_len = strpos($this->buffer, "\r\n"); | $header_len = @strpos($this->buffer, "\r\n"); | ||||
if ($header_len === false) { | if ($header_len === false) { | ||||
// We don't have a full header yet, so wait for more data. | // We don't have a full header yet, so wait for more data. | ||||
$continue = false; | $continue = false; | ||||
break; | break; | ||||
} | } | ||||
$header_buf = substr($this->buffer, 0, $header_len); | $header_buf = @substr($this->buffer, 0, $header_len); | ||||
$this->part->appendRawHeader($header_buf); | $this->part->appendRawHeader($header_buf); | ||||
$this->buffer = substr($this->buffer, $header_len + 2); | $this->buffer = @substr($this->buffer, $header_len + 2); | ||||
break; | break; | ||||
case 'body': | case 'body': | ||||
// We've parsed a boundary and headers, and are parsing the data for | // We've parsed a boundary and headers, and are parsing the data for | ||||
Context not available. | |||||
// we find it. | // we find it. | ||||
$marker = "\r"; | $marker = "\r"; | ||||
$marker_pos = strpos($this->buffer, $marker); | $marker_pos = @strpos($this->buffer, $marker); | ||||
if ($marker_pos === false) { | if ($marker_pos === false) { | ||||
// There's no "\r" anywhere in the buffer, so we can just read it | // There's no "\r" anywhere in the buffer, so we can just read it | ||||
Context not available. | |||||
if ($marker_pos > 0) { | if ($marker_pos > 0) { | ||||
// If there are bytes before the "\r", | // If there are bytes before the "\r", | ||||
if ($this->part) { | if ($this->part) { | ||||
$this->part->appendData(substr($this->buffer, 0, $marker_pos)); | $this->part->appendData(@substr($this->buffer, 0, $marker_pos)); | ||||
} | } | ||||
$this->buffer = substr($this->buffer, $marker_pos); | $this->buffer = @substr($this->buffer, $marker_pos); | ||||
} | } | ||||
$expect = "\r\n"; | $expect = "\r\n"; | ||||
$expect_len = strlen($expect); | $expect_len = @strlen($expect); | ||||
if (strlen($this->buffer) < $expect_len) { | if (@strlen($this->buffer) < $expect_len) { | ||||
// We don't have enough bytes yet to know if this is "\r\n" | // We don't have enough bytes yet to know if this is "\r\n" | ||||
// or not. | // or not. | ||||
$continue = false; | $continue = false; | ||||
Context not available. | |||||
// The next two bytes aren't "\r\n", so eat them and go looking | // The next two bytes aren't "\r\n", so eat them and go looking | ||||
// for more newlines. | // for more newlines. | ||||
if ($this->part) { | if ($this->part) { | ||||
$this->part->appendData(substr($this->buffer, 0, $expect_len)); | $this->part->appendData(@substr($this->buffer, 0, $expect_len)); | ||||
} | } | ||||
$this->buffer = substr($this->buffer, $expect_len); | $this->buffer = @substr($this->buffer, $expect_len); | ||||
break; | break; | ||||
} | } | ||||
// Eat the "\r\n". | // Eat the "\r\n". | ||||
$this->buffer = substr($this->buffer, $expect_len); | $this->buffer = @substr($this->buffer, $expect_len); | ||||
$this->state = 'bodynewline'; | $this->state = 'bodynewline'; | ||||
break; | break; | ||||
case 'bodynewline': | case 'bodynewline': | ||||
Context not available. | |||||
// bytes and move on. | // bytes and move on. | ||||
$expect = '--'.$this->boundary; | $expect = '--'.$this->boundary; | ||||
$expect_len = strlen($expect); | $expect_len = @strlen($expect); | ||||
if (strlen($this->buffer) < $expect_len) { | if (@strlen($this->buffer) < $expect_len) { | ||||
// We don't have enough bytes yet, so wait for more. | // We don't have enough bytes yet, so wait for more. | ||||
$continue = false; | $continue = false; | ||||
break; | break; | ||||
Context not available. | |||||
} | } | ||||
// This is the boundary, so toss it and move on. | // This is the boundary, so toss it and move on. | ||||
$this->buffer = substr($this->buffer, $expect_len); | $this->buffer = @substr($this->buffer, $expect_len); | ||||
$this->state = 'endboundary'; | $this->state = 'endboundary'; | ||||
break; | break; | ||||
case 'epilogue': | case 'epilogue': | ||||
Context not available. |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0