[DO NOT MERGE] Throw exception if slot has invalid offset

Previously the process would crash, which is OK, but complicates testing.

Test: cts-tradefed run cts --module CtsContentTestCases
      --test android.content.cts.ContentProviderCursorWindowTest
Bug: 34128677

Change-Id: I5b50982d77ec65c442fbb973d14c85a5c29c43c7
(cherry picked from commit eb6de6f5f1)
This commit is contained in:
Fyodor Kupolov
2017-02-22 14:12:50 -08:00
parent 3e4faac39f
commit 69e347f7ef

View File

@@ -180,6 +180,10 @@ static jbyteArray nativeGetBlob(JNIEnv* env, jclass clazz, jlong windowPtr,
if (type == CursorWindow::FIELD_TYPE_BLOB || type == CursorWindow::FIELD_TYPE_STRING) { if (type == CursorWindow::FIELD_TYPE_BLOB || type == CursorWindow::FIELD_TYPE_STRING) {
size_t size; size_t size;
const void* value = window->getFieldSlotValueBlob(fieldSlot, &size); const void* value = window->getFieldSlotValueBlob(fieldSlot, &size);
if (!value) {
throw_sqlite3_exception(env, "Native could not read blob slot");
return NULL;
}
jbyteArray byteArray = env->NewByteArray(size); jbyteArray byteArray = env->NewByteArray(size);
if (!byteArray) { if (!byteArray) {
env->ExceptionClear(); env->ExceptionClear();
@@ -215,6 +219,10 @@ static jstring nativeGetString(JNIEnv* env, jclass clazz, jlong windowPtr,
if (type == CursorWindow::FIELD_TYPE_STRING) { if (type == CursorWindow::FIELD_TYPE_STRING) {
size_t sizeIncludingNull; size_t sizeIncludingNull;
const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull);
if (!value) {
throw_sqlite3_exception(env, "Native could not read string slot");
return NULL;
}
if (sizeIncludingNull <= 1) { if (sizeIncludingNull <= 1) {
return gEmptyString; return gEmptyString;
} }