{"record":{"id":"b9dae1a2505cd917","repo":"microg/GmsCore","slug":"length-of-flags-is-smaller-than-length-min-securit","errorCode":null,"errorMessage":"length of flags is smaller than LENGTH_MIN_SECURITY_POLICY_FLAGS","messagePattern":"length of flags is smaller than LENGTH_MIN_SECURITY_POLICY_FLAGS","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-threadnetwork/src/main/java/com/google/android/gms/threadnetwork/ThreadNetworkCredentials.java","lineNumber":178,"sourceCode":"\n    /**\n     * The class represents Thread Security Policy.\n     */\n    public static class SecurityPolicy {\n        private final int rotationTimeHours;\n        private final byte[] flags;\n\n        /**\n         * Creates a new {@link SecurityPolicy} object.\n         *\n         * @param rotationTimeHours the value for Thread key rotation in hours. Must be in range of 0x1-0xffff.\n         * @param flags             security policy flags with length of either 1 byte for Thread 1.1 or 2 bytes for Thread 1.2 or higher.\n         * @throws IllegalArgumentException if {@code rotationTimeHours} is not in range of 0x1-0xffff or\n         *                                  length of flags is smaller than {@link ThreadNetworkCredentials#LENGTH_MIN_SECURITY_POLICY_FLAGS}.\n         */\n        public SecurityPolicy(int rotationTimeHours, byte[] flags) {\n            if (rotationTimeHours < 1 || rotationTimeHours > 0xffff) throw new IllegalArgumentException(\"rotationTimeHours is not in range of 0x1-0xffff\");\n            if (flags.length < LENGTH_MIN_SECURITY_POLICY_FLAGS) throw new IllegalArgumentException(\"length of flags is smaller than LENGTH_MIN_SECURITY_POLICY_FLAGS\");\n            this.rotationTimeHours = rotationTimeHours;\n            this.flags = flags;\n        }\n\n        /**\n         * Returns 1 byte flags for Thread 1.1 or 2 bytes flags for Thread 1.2.\n         */\n        public byte[] getFlags() {\n            return flags;\n        }\n\n        /**\n         * Returns the Security Policy Rotation Time in hours.\n         */\n        public int getRotationTimeHours() {\n            return rotationTimeHours;\n        }\n    }","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-threadnetwork/src/main/java/com/google/android/gms/threadnetwork/ThreadNetworkCredentials.java#L160-L196","documentation":"ThreadNetworkCredentials.SecurityPolicy's constructor requires the flags array to be at least LENGTH_MIN_SECURITY_POLICY_FLAGS bytes (1 byte for Thread 1.1, 2 for Thread 1.2+) and throws IllegalArgumentException if shorter. The flags field in the Thread dataset has a specification-defined minimum length that must be honored.","triggerScenarios":"Passing a byte[] flags with length 0 or shorter than LENGTH_MIN_SECURITY_POLICY_FLAGS — e.g. an empty array, a truncated decode, or confusing the flags count with the array length.","commonSituations":"Building SecurityPolicy before populating flags; hex/base64 decode of flags dropping bytes; passing individual flag values instead of a byte array.","solutions":["Ensure flags is at least LENGTH_MIN_SECURITY_POLICY_FLAGS bytes long before constructing","Use a 1-byte array for Thread 1.1 and a 2-byte array for Thread 1.2+ networks","Check the array construction — e.g. new byte[]{flagByte} instead of an empty array","Read LENGTH_MIN_SECURITY_POLICY_FLAGS from ThreadNetworkCredentials rather than hardcoding"],"exampleFix":"// before\nSecurityPolicy policy = new SecurityPolicy(672, new byte[0]); // IllegalArgumentException\n// after\nbyte[] flags = new byte[] { (byte) 0xFF }; // 1 byte for Thread 1.1 (2 bytes for 1.2+)\nSecurityPolicy policy = new SecurityPolicy(672, flags);","handlingStrategy":"validation","validationCode":"if (flags == null || flags.length < ThreadNetworkCredentials.LENGTH_MIN_SECURITY_POLICY_FLAGS) throw new IllegalArgumentException(\"flags too short\");","typeGuard":"boolean isValidFlags(byte[] flags) { return flags != null && flags.length >= 1; }","tryCatchPattern":"try {\n    SecurityPolicy p = new SecurityPolicy(rotationTimeHours, flags);\n} catch (IllegalArgumentException e) {\n    // supply a correctly sized flags array\n}","preventionTips":["Size flags per Thread version: 1 byte for 1.1, 2 bytes for 1.2+","Never pass empty arrays; build with new byte[]{...}","Reference LENGTH_MIN_SECURITY_POLICY_FLAGS instead of hardcoding lengths"],"tags":["thread-network","validation","byte-array","java"],"backgroundTag":"invalid-argument-value","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}