fix buffer overflow

This commit is contained in:
Hannes Janetzek 2012-12-06 23:45:44 +01:00
parent d5b480cf22
commit 3c5efd17bd

View File

@ -600,9 +600,11 @@ public class MapDatabase implements IMapDatabase {
private int readBuffer(int size) throws IOException { private int readBuffer(int size) throws IOException {
int read = 0; int read = 0;
// check if buffer already contains the request bytes
if (mBufferPos + size < mBufferSize) if (mBufferPos + size < mBufferSize)
return mBufferSize - mBufferPos; return mBufferSize - mBufferPos;
// check if inputstream is read to the end
if (mReadPos == mContentLenth) if (mReadPos == mContentLenth)
return mBufferSize - mBufferPos; return mBufferSize - mBufferPos;
@ -617,8 +619,11 @@ public class MapDatabase implements IMapDatabase {
if (mBufferSize == mBufferPos) { if (mBufferSize == mBufferPos) {
mBufferPos = 0; mBufferPos = 0;
mBufferSize = 0; mBufferSize = 0;
} else if (mBufferPos + (size - mBufferSize) > BUFFER_SIZE) { } else if (mBufferPos + size > BUFFER_SIZE) {
Log.d(TAG, "wrap buffer" + (size - mBufferSize) + " " + mBufferPos); // Log.d(TAG, "wrap buffer - read:" + size
// + " cur size:" + mBufferSize
// + " cur pos:" + mBufferPos);
// copy bytes left to read to the beginning of buffer // copy bytes left to read to the beginning of buffer
mBufferSize -= mBufferPos; mBufferSize -= mBufferPos;
System.arraycopy(mReadBuffer, mBufferPos, mReadBuffer, 0, mBufferSize); System.arraycopy(mReadBuffer, mBufferPos, mReadBuffer, 0, mBufferSize);