{"record":{"id":"63d720bc889838e4","repo":"NationalSecurityAgency/ghidra","slug":"bad-vectable-rowid","errorCode":null,"errorMessage":"Bad vectable rowid","messagePattern":"Bad vectable rowid","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java","lineNumber":539,"sourceCode":"\t\t\t}\n\t\t\tSimilarityVectorResult simres = new SimilarityVectorResult(frec);\n\t\t\tsimres.addNotes(resultset);\n\t\t\tresponse.totalmatch += simres.getTotalCount();\n\t\t\tif (simres.getTotalCount() == 1) {\n\t\t\t\tresponse.uniquematch += 1;\n\t\t\t}\n\t\t\tresponse.result.add(simres);\n\t\t}\n\t}\n\n\t@Override\n\tprotected VectorResult queryVectorId(long id) throws SQLException {\n\t\tPreparedStatement s = selectVectorByRowIdStatement.prepareIfNeeded(() -> initConnection()\n\t\t\t\t.prepareStatement(\"SELECT id,count,vec FROM vectable WHERE id = ?\"));\n\t\ts.setLong(1, id);\n\t\ttry (ResultSet rs = s.executeQuery()) {\n\t\t\tif (!rs.next()) {\n\t\t\t\tthrow new SQLException(\"Bad vectable rowid\");\n\t\t\t}\n\t\t\tVectorResult rowres;\n\t\t\ttry {\n\t\t\t\trowres = new VectorResult();\n\t\t\t\trowres.vectorid = rs.getLong(1);\n\t\t\t\trowres.hitcount = rs.getInt(2);\n\t\t\t\trowres.vec = vectorFactory.restoreVectorFromSql(rs.getString(3));\n\t\t\t}\n\t\t\tcatch (final IOException e) {\n\t\t\t\tthrow new SQLException(e.getMessage());\n\t\t\t}\n\n\t\t\treturn rowres;\n\t\t}\n\n\t}\n\n\t@Override","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java#L521-L557","documentation":"Thrown by PostgresFunctionDatabase.queryVectorId() when a SELECT by the given row id returns no rows from the vectable. This means no vector record exists with the requested id — the id is stale, was already deleted, or never existed.","triggerScenarios":"Calling queryVectorId(id) with an id that does not correspond to any row in vectable. This occurs when a previously obtained vector id references a row that was subsequently removed (e.g. by deleteVectors reducing count to zero), or when an invalid/zero id is passed.","commonSituations":"A SignatureRecord's vector id was deleted by a concurrent or prior operation. A reference to a vector id was persisted and the underlying row was cleaned up. An off-by-one or uninitialized id (e.g. 0 or -1) is passed accidentally.","solutions":["Verify the vector id is valid and the corresponding vectable row still exists before querying.","If the row may have been deleted, handle the missing-row case gracefully in the caller.","Ensure no concurrent process is deleting vectors that this query depends on."],"exampleFix":"// before\nVectorResult vr = db.queryVectorId(id); // throws \"Bad vectable rowid\" if deleted\n\n// after — guard against stale id\n// (check existence first, or catch SQLException)\ntry {\n    VectorResult vr = db.queryVectorId(id);\n} catch (SQLException e) {\n    if (e.getMessage().contains(\"Bad vectable rowid\")) {\n        // vector was deleted; handle gracefully\n    } else throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Verify the vector id still exists before querying\n// (requires a separate existence check or tracking deletion state)\n// If you have access to a connection:\n// SELECT 1 FROM vectable WHERE id = ?","typeGuard":null,"tryCatchPattern":"try {\n    VectorResult vr = db.queryVectorId(id);\n} catch (SQLException e) {\n    if (e.getMessage().equals(\"Bad vectable rowid\")) {\n        // vector was deleted or id is invalid; handle gracefully\n        return null;\n    }\n    throw e;\n}","preventionTips":["Track which vector ids have been deleted to avoid stale lookups.","Validate that an id is non-zero and within expected range before querying.","Handle missing-vector gracefully if concurrent deletions are possible."],"tags":["bsim","ghidra","postgresql","database","data-missing","vectable"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}