{"record":{"id":"feeca4d5b934ecd6","repo":"FuelLabs/fuels-ts","slug":"decode-error-feeca4","errorCode":"DECODE_ERROR","errorMessage":"Invalid vec data size.","messagePattern":"Invalid vec data size\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/VecCoder.ts","lineNumber":50,"sourceCode":"        `Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`\n      );\n    }\n\n    const lengthCoder = new BigNumberCoder('u64');\n\n    if (isUint8Array(value)) {\n      return new Uint8Array([...lengthCoder.encode(value.length), ...value]);\n    }\n\n    const bytes = value.map((v) => this.coder.encode(v));\n    const lengthBytes = lengthCoder.encode(value.length);\n\n    return new Uint8Array([...lengthBytes, ...concatBytes(bytes)]);\n  }\n\n  decode(data: Uint8Array, offset: number): [DecodedValueOf<TCoder>, number] {\n    if ((!this.#hasNestedOption && data.length < this.encodedLength) || data.length > MAX_BYTES) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);\n    }\n\n    const offsetAndLength = offset + WORD_SIZE;\n    const lengthBytes = data.slice(offset, offsetAndLength);\n    const length = bn(new BigNumberCoder('u64').decode(lengthBytes, 0)[0]).toNumber();\n    const dataLength = length * this.coder.encodedLength;\n    const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength);\n\n    if (!this.#hasNestedOption && dataBytes.length !== dataLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);\n    }\n\n    let newOffset = offsetAndLength;\n    const chunks = [];\n    for (let i = 0; i < length; i++) {\n      const [decoded, optionOffset] = this.coder.decode(data, newOffset);\n      chunks.push(decoded);\n      newOffset = optionOffset;","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/VecCoder.ts#L32-L68","documentation":"Thrown by VecCoder.decode() under two conditions: (1) the vector has no nested Option fields and the data buffer is shorter than WORD_SIZE (8 bytes), too small to read the u64 element-count prefix; or (2) the data buffer exceeds MAX_BYTES (2^32 - 1), a safety guard against unreasonably large or potentially malicious payloads. Both indicate the data cannot be safely decoded.","triggerScenarios":"Passing fewer than 8 bytes to decode(), failing the minimum-size check. Receiving a corrupted or adversarial payload whose total size exceeds MAX_BYTES (approximately 4 GB). Both conditions indicate data that is either truncated or dangerously oversized.","commonSituations":"Truncated RPC data failing the minimum-size check. Corrupted or adversarial data triggering the MAX_BYTES guard. Memory exhaustion scenarios with very large vectors from untrusted sources.","solutions":["Verify data.length is between 8 and MAX_BYTES before calling decode().","Validate data size from untrusted sources before attempting to decode.","Check for truncation or corruption in the data pipeline."],"exampleFix":"// before\nvecCoder.decode(new Uint8Array([0, 1, 2]), 0); // throws DECODE_ERROR\n\n// after\nconst MAX_BYTES = 2 ** 32 - 1;\nif (data.length < 8 || data.length > MAX_BYTES) {\n  throw new Error('Invalid vec data size');\n}\nvecCoder.decode(data, 0);","handlingStrategy":"validation","validationCode":"const MAX_BYTES = 2 ** 32 - 1;\nfunction canDecodeVec(data: Uint8Array): boolean {\n  return data.length >= 8 && data.length <= MAX_BYTES;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const [decoded, offset] = vecCoder.decode(data, 0);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.DECODE_ERROR) {\n    // data too short or exceeds MAX_BYTES; reject the payload\n  }\n  throw e;\n}","preventionTips":["Size-check all incoming ABI payloads before decoding.","Treat MAX_BYTES violations as potential DoS attempts from untrusted sources.","Validate the u64 length prefix against reasonable application-level limits."],"tags":["abi-coder","decoding","vec","data-validation","dos-prevention"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}