{"record":{"id":"069509d3dd7562cc","repo":"java-native-access/jna","slug":"invalid-data-length","errorCode":null,"errorMessage":"Invalid data length: ","messagePattern":"Invalid data length: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Guid.java","lineNumber":207,"sourceCode":"                && (this.Data3 == other.Data3)\n                && Arrays.equals(this.Data4, other.Data4);\n        }\n\n        @Override\n        public int hashCode() {\n            return this.Data1 + this.Data2 & 0xFFFF + this.Data3 & 0xFFFF + Arrays.hashCode(this.Data4);\n        }\n\n        /**\n         * From binary.\n         *\n         * @param data\n         *            the data\n         * @return the guid\n         */\n        public static GUID fromBinary(byte[] data) {\n            if (data.length != 16) {\n                throw new IllegalArgumentException(\"Invalid data length: \"\n                        + data.length);\n            }\n\n            GUID newGuid = new GUID();\n            long data1Temp = data[0] & 0xff;\n            data1Temp <<= 8;\n            data1Temp |= data[1] & 0xff;\n            data1Temp <<= 8;\n            data1Temp |= data[2] & 0xff;\n            data1Temp <<= 8;\n            data1Temp |= data[3] & 0xff;\n            newGuid.Data1 = (int) data1Temp;\n\n            int data2Temp = data[4] & 0xff;\n            data2Temp <<= 8;\n            data2Temp |= data[5] & 0xff;\n            newGuid.Data2 = (short) data2Temp;\n","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Guid.java#L189-L225","documentation":"Validation guard in GUID.fromBinary: it fires because the byte array passed in is not exactly 16 bytes long, which is the fixed binary size of a Windows GUID (4+2+2+8 bytes). Any other length cannot be deserialized into a GUID.","triggerScenarios":"Passing a byte[] from a truncated buffer, a GUID string converted without accounting for formatting, or an array read from a stream with fewer/more than 16 bytes into fromBinary.","commonSituations":"Reading GUIDs from files or network payloads with wrong offsets; converting a 36-char UUID string to bytes directly (36 bytes) instead of parsing; mixing little-endian serialized blobs of other sizes.","solutions":["Ensure the byte array is exactly 16 bytes: slice it (Arrays.copyOfRange(data, off, off+16)) or validate data.length before calling","Parse GUID strings with GUID.fromString (or fromStringIID) instead of manual byte conversion","Check the serialization/source format — the producer may be writing a different structure than a raw 16-byte GUID"],"exampleFix":"// before\nGUID g = GUID.fromBinary(blob);\n// after\nif (blob.length != 16) {\n    throw new IllegalArgumentException(\"expected 16-byte GUID, got \" + blob.length);\n}\nGUID g = GUID.fromBinary(Arrays.copyOfRange(blob, 0, 16));","handlingStrategy":"validation","validationCode":"public static GUID safeFromBinary(byte[] data) {\n    if (data == null || data.length != 16)\n        throw new IllegalArgumentException(\"GUID needs exactly 16 bytes, got \" + (data == null ? \"null\" : data.length));\n    return GUID.fromBinary(data);\n}","typeGuard":"boolean is16Bytes(byte[] b) {\n    return b != null && b.length == 16;\n}","tryCatchPattern":"try {\n    GUID g = GUID.fromBinary(data);\n} catch (IllegalArgumentException e) {\n    // data.length != 16 — fix the slice/source offsets\n    log.error(\"Bad GUID blob: \" + e.getMessage());\n}","preventionTips":["Always slice exactly 16 bytes (Arrays.copyOfRange) before fromBinary","Prefer GUID.fromString for string inputs instead of manual byte conversion","Validate producer serialization format writes raw 128-bit GUIDs"],"tags":["java","win32","guid","byte-array","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}