From 943b310c90ad5e96395c4d33cb996774959a1cda Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 31 Mar 2014 09:59:12 +0200 Subject: [PATCH] Data URLs: fix size computation. The decoded data is 3/4 the size of base64 encoded, not 4/3. --- src/kits/network/libnetapi/DataRequest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/kits/network/libnetapi/DataRequest.cpp b/src/kits/network/libnetapi/DataRequest.cpp index b2fd9002a3..4b394d959f 100644 --- a/src/kits/network/libnetapi/DataRequest.cpp +++ b/src/kits/network/libnetapi/DataRequest.cpp @@ -81,7 +81,7 @@ BDataRequest::_ProtocolLoop() } if (isBase64) { - char* buffer = new char[data.Length() * 4 / 3]; + char* buffer = new char[data.Length() * 3 / 4]; payload = buffer; // payload must be a const char* so we can assign data.String() to // it below, but decode_64 modifies buffer. @@ -90,8 +90,8 @@ BDataRequest::_ProtocolLoop() // There may be some padding at the end of the base64 stream. This // prevents us from computing the exact length we should get, so allow // for some error margin. - if(length > data.Length() * 4 / 3 - || length < data.Length() * 4 / 3 - 3) { + if(length > data.Length() * 3 / 4 + || length < data.Length() * 3 / 4 - 3) { delete[] buffer; return B_BAD_DATA; }