microg/GmsCore · error · IllegalArgumentException

Invalid image data size

Error message

Invalid image data size

What it means

Size validation in Frame.Builder.setImageData: the byte buffer's remaining capacity does not match width * height * bytes-per-pixel for the chosen format, so the data cannot describe the claimed image dimensions.

Source

Thrown at play-services-vision-common/src/main/java/com/google/android/gms/vision/Frame.java:125

         * A {@link Detector.Processor} implementation may rely upon this sequence ID to detect frame sequence gaps, to compute velocity, etc.
         */
        public Builder setId(int id) {
            this.frame.metadata.id = id;
            return this;
        }

        /**
         * Sets the image data from the supplied byte buffer, size, and format.
         *
         * @param data   contains image byte data according to the associated format.
         * @param width
         * @param height
         * @param format one of {@link ImageFormat#NV16}, {@link ImageFormat#NV21}, or {@link ImageFormat#YV12}.
         * @throws IllegalArgumentException if the supplied data is null, or an invalid image format was supplied.
         */
        public Builder setImageData(ByteBuffer data, int width, int height, int format) {
            if (data == null) throw new IllegalArgumentException("Null image data supplied");
            if (data.capacity() < width * height) throw new IllegalArgumentException("Invalid image data size");
            if (format != ImageFormat.NV16 && format != ImageFormat.NV21 && format != ImageFormat.YV12)
                throw new IllegalArgumentException("Unsupported image format: " + format);
            this.frame.imageData = data;
            this.frame.metadata.width = width;
            this.frame.metadata.height = height;
            this.frame.metadata.format = format;
            return this;
        }

        /**
         * Sets the image rotation, indicating the rotation from the upright orientation.
         * <p>
         * Since the camera may deliver images that are rotated (e.g., if the user holds the device upside down), specifying the rotation with the image indicates how to make the image be upright, if necessary. Some detectors may rely upon rotating the image before attempting detection, whereas others may not. In preserving the original image from the camera along with this value, the detector may choose whether to make this correction (and to assume the associated cost).
         * <p>
         * However, note that the detector is expected to report detection position coordinates that are relative to the upright version of the image (whether or not the image was actually rotated by the detector). The {@link Detector} will always deliver frame metadata to the {@link Detector.Processor} that indicates the dimensions and orientation of an unrotated, upright frame.
         *
         * @param rotation one of {@link Frame#ROTATION_0}, {@link Frame#ROTATION_90}, {@link Frame#ROTATION_180}, {@link Frame#ROTATION_270}. Has the same meaning as {@link Display#getRotation()}.
         */

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Size the buffer to exactly width*height*bytesPerPixel for the image format
  2. Fix mismatched width/height values passed alongside the buffer
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at play-services-vision-common/src/main/java/com/google/android/gms/vision/Frame.java:125 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/58f660d974c8a749. Report an issue: GitHub.