From c4a59a7a5fb9c07bebf24ed6fac40a35ddc4535f Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 10 Dec 2024 16:28:28 -0500 Subject: [PATCH] file_systems/QueryParser: Don't try to read the key size of invalid indexes. Fixes a rare corner case. --- headers/private/file_systems/QueryParser.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/headers/private/file_systems/QueryParser.h b/headers/private/file_systems/QueryParser.h index e7e3791135..6278c52b9e 100644 --- a/headers/private/file_systems/QueryParser.h +++ b/headers/private/file_systems/QueryParser.h @@ -805,6 +805,7 @@ Equation::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::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::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;