{"record":{"id":"4834978bf2b4881d","repo":"NationalSecurityAgency/ghidra","slug":"taintvecs-must-match-in-length","errorCode":null,"errorMessage":"TaintVecs must match in length","messagePattern":"TaintVecs must match in length","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/TaintAnalysis/src/main/java/ghidra/taint/model/TaintVec.java","lineNumber":213,"sourceCode":"\t\treturn this;\n\t}\n\n\t/**\n\t * Perform an operation on each same-indexed element from this and another vector, forming a\n\t * third result vector\n\t * \n\t * <p>\n\t * In essence return, a vector where {@code result[n] = this[n] op that[n]}. The two input\n\t * vectors must match in length.\n\t * \n\t * @param that the other vector\n\t * @param op the operation to apply\n\t * @return the result\n\t */\n\tprivate TaintVec zip(TaintVec that, BinaryOperator<TaintSet> op) {\n\t\tfinal int length = this.sets.length;\n\t\tif (length != that.sets.length) {\n\t\t\tthrow new IllegalArgumentException(\"TaintVecs must match in length\");\n\t\t}\n\t\tTaintVec vec = new TaintVec(length);\n\t\tfor (int i = 0; i < length; i++) {\n\t\t\tvec.sets[i] = op.apply(this.sets[i], that.sets[i]);\n\t\t}\n\t\treturn vec;\n\t}\n\n\t/**\n\t * Perform an operation on a given taint set and each element from this array, forming a result\n\t * vector\n\t * \n\t * <p>\n\t * In essence, return a vector where {@code result[n] = this[n] op set}.\n\t * \n\t * @param set the taint set\n\t * @param op the operation to apply\n\t * @return the result","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/TaintAnalysis/src/main/java/ghidra/taint/model/TaintVec.java#L195-L231","documentation":"TaintVec.zip performs an element-wise combination result[n] = this[n] op that[n], so both input vectors must have identical length to keep indices aligned. A length mismatch throws IllegalArgumentException. This guards every binary taint op (union/intersection of two operand vectors).","triggerScenarios":"Applying a binary taint operation to two TaintVecs whose internal sets[] arrays differ in length - e.g. operands of different byte sizes, or a constant that wasn't broadcast/extended to the right length before the op.","commonSituations":"Mismatched operand sizes from pcode (adding an 8-byte vec to a 4-byte vec); a fromConst that produced the wrong element count; a vectorization/extension bug that left operands unequal in length.","solutions":["Ensure both operands share the same byte length (use TaintVec.empties(n) and a correctly-sized fromConst).","Broadcast or extend the shorter vector to match the longer one before combining.","Trace the producing pcode op to confirm the input sizes and fix upstream sizing."],"exampleFix":"// before\nTaintVec sum = a.zip(b, TaintSet::union); // throws if a.length != b.length\n// after\nint n = Math.max(a.length, b.length);\nTaintVec ae = a.extend(n);\nTaintVec be = b.extend(n);\nTaintVec sum = ae.zip(be, TaintSet::union);","handlingStrategy":"validation","validationCode":"if (a.length != b.length) {\n    // extend/broadcast before combining\n    int n = Math.max(a.length, b.length);\n    a = a.extend(n);\n    b = b.extend(n);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate TaintVec lengths before binary ops.","Ensure constants are created with the correct element count via fromConst/empties(n)."],"tags":["pcode","emulation","taint","validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}