diff --git a/core/postmultiparser.cpp b/core/postmultiparser.cpp index 0772c50..db115c9 100755 --- a/core/postmultiparser.cpp +++ b/core/postmultiparser.cpp @@ -238,16 +238,24 @@ size_t i; void PostMultiParser::ReadContentSkipBoundary(bool has_boundary) { - if( has_boundary ) + if( has_boundary && content.size() >= boundary.size() ) + { content.erase(content.size()-boundary.size()); + content_len -= boundary.size(); + } // the last new line character doesn't belong to the content + // this is a new line character before the boundary if( !content.empty() && content[content.size()-1] == 10 ) { content.erase(content.size()-1); + content_len -= 1; if( line_end_dos && !content.empty() && content[content.size()-1] == 13 ) + { content.erase(content.size()-1); + content_len -= 1; + } } } @@ -260,12 +268,12 @@ bool has_boundary = false; while( last!=-1 && !(has_boundary=HasBoundary()) ) { content += last; + content_len += 1; ReadChar(); if( content.size() > WINIX_POSTMULTI_OUTPUT_BUFFER + boundary.size() + 2 ) // +2 for the new line character { tmp_file.write(content.c_str(), WINIX_POSTMULTI_OUTPUT_BUFFER); - content_len += WINIX_POSTMULTI_OUTPUT_BUFFER; content.erase(0, WINIX_POSTMULTI_OUTPUT_BUFFER); } @@ -283,7 +291,6 @@ bool has_boundary = false; if( !content.empty() ) { tmp_file.write(content.c_str(), content.size()); - content_len += content.size(); content.clear(); } }