Data URLs: fix size computation.

The decoded data is 3/4 the size of base64 encoded, not 4/3.
This commit is contained in:
Adrien Destugues
2014-03-31 09:59:12 +02:00
parent aec5be7aa2
commit 943b310c90
+3 -3
View File
@@ -81,7 +81,7 @@ BDataRequest::_ProtocolLoop()
} }
if (isBase64) { if (isBase64) {
char* buffer = new char[data.Length() * 4 / 3]; char* buffer = new char[data.Length() * 3 / 4];
payload = buffer; payload = buffer;
// payload must be a const char* so we can assign data.String() to // payload must be a const char* so we can assign data.String() to
// it below, but decode_64 modifies buffer. // 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 // 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 // prevents us from computing the exact length we should get, so allow
// for some error margin. // for some error margin.
if(length > data.Length() * 4 / 3 if(length > data.Length() * 3 / 4
|| length < data.Length() * 4 / 3 - 3) { || length < data.Length() * 3 / 4 - 3) {
delete[] buffer; delete[] buffer;
return B_BAD_DATA; return B_BAD_DATA;
} }