file_systems/QueryParser: Don't try to read the key size of invalid indexes.

Fixes a rare corner case.
This commit is contained in:
Augustin Cavalier
2024-12-10 16:28:28 -05:00
parent f63a4a17ea
commit c4a59a7a5f
+9 -2
View File
@@ -805,6 +805,7 @@ Equation<QueryPolicy>::PrepareQuery(Context* /*context*/, Index& index,
return B_ENTRY_NOT_FOUND;
type_code type;
int32 keySize;
// Special case for OP_UNEQUAL - it will always operate through the whole
// index but we need the call to the original index to get the correct type
@@ -812,7 +813,13 @@ Equation<QueryPolicy>::PrepareQuery(Context* /*context*/, Index& index,
// Try to get an index that holds all files (name)
// Also sets the default type for all attributes without index
// to string.
type = status < B_OK ? B_STRING_TYPE : QueryPolicy::IndexGetType(index);
if (status == B_OK) {
type = QueryPolicy::IndexGetType(index);
keySize = QueryPolicy::IndexGetKeySize(index);
} else {
type = B_STRING_TYPE;
keySize = 0;
}
if (QueryPolicy::IndexSetTo(index, "name") != B_OK)
return B_ENTRY_NOT_FOUND;
@@ -821,9 +828,9 @@ Equation<QueryPolicy>::PrepareQuery(Context* /*context*/, Index& index,
} else {
fHasIndex = true;
type = QueryPolicy::IndexGetType(index);
keySize = QueryPolicy::IndexGetKeySize(index);
}
int32 keySize = QueryPolicy::IndexGetKeySize(index);
if (ConvertValue(type, keySize) < B_OK)
return B_BAD_VALUE;