Skip to content

Uploads larger than 2GB fail #2686

@daxmitchell

Description

@daxmitchell

Expected behavior

When uploading files less than 2GB, the transfer goes through fine. With files larger than 2GB, we would expect the same behavior.

It seems the only fix is to remove the cast to int (please see below, in Actual behavior section). Any suggestions for workarounds would be deeply appreciated.

Actual behavior

For files larger than 2GB, uploads fail. This appears to be due to an integer overflow problem.

In particular, the static_cast fails in the following line of Net::HTMLForm:

pCountingOutputStream->addChars(static_cast<int>(partlen));

it seems the cast is unnecessary. When I removed the cast (see below), the upload succeeds

pCountingOutputStream->addChars(partlen);

Steps to reproduce the problem

The code below illustrates the issue:

Poco::URI uri(myUrl);
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, uri.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_0); 
Poco::Net::HTMLForm form;
form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
form.prepareSubmit(request);
Poco::Net::HTTPClientSession session;
session.reset(new Poco::Net::HTTPSClientSession(uri.getHost(), uri.getPort()));
std::ostream& ostream = session->sendRequest(request);  // CODE FAILS HERE
form.write(ostream); 

The exception is printed below:


Not a valid integer: 18446744072884299464
backtrace (entry 1 skipped):

poco/1.7.8c/linux-x86_64-2.12/gnu7.1/libPocoFoundation.so.80:
 2 Poco::Exception::Exception(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)+0x95
 3 Poco::RuntimeException::RuntimeException(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)+0x9
 4 Poco::DataException::DataException(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)+0x9
 5 Poco::SyntaxException::SyntaxException(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)+0x9
 6 Poco::NumberParser::parse64(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char)+0x5c
 7 Poco::Net::HTTPClientSession::sendRequest(Poco::Net::HTTPRequest&)+0x564
 8 <our POCO client code>

POCO version

Can reproduce the problem with 1.7.8c, also can reproduce with the latest master

Compiler and version

gnu g++ 7.1

Operating system and version

CentOS 7.6

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions