Skip to content

getBytes does not validate ivLength, may throw NegativeArraySizeException #619

Open

Description

@AbdelrahmanWM

Please agree to the following

Summary

The getBytes method in CryptoByteArrayUtils does not validate the ivLength argument. If ivLength is larger than the input array length, the method will throw a NegativeArraySizeException when creating the result array.

System Setup

- Android: 35 (target SDK)
- Cryptomator: 1.13.0-SNAPSHOT

Cloud Type

No response

Steps to Reproduce

byte[] data = new byte[5];
CryptoByteArrayUtils.getBytes(data, 10);

Expected Behavior

An IllegalArgumentException should be thrown with a descriptive message like "ivLength must not exceed input array length".

Actual Behavior

NegativeArraySizeException is thrown.

Reproducibility

Always

Relevant Log Output

Anything else?

Target method

public static byte[] getBytes(byte[] encryptedBytesWithIv, int ivLength) {
		if (encryptedBytesWithIv == null) {
			throw new IllegalArgumentException("Input array must not be null");
		}
		byte[] bytes = new byte[encryptedBytesWithIv.length - ivLength];
		System.arraycopy(encryptedBytesWithIv, ivLength, bytes, 0, bytes.length);
		return bytes;
	}

unit test used

@Test
		void testGetBytes_withIvLengthGreaterThanArrayLength_shouldThrow() {
			byte[] input = {1, 2, 3};
			int ivLength = 5; // greater than input length

			assertThrows(NegativeArraySizeException.class, () -> {
				CryptoByteArrayUtils.getBytes(input, ivLength);
			});
		}

Activity

  1. added
    type:bug
    on Nov 11, 2025
  2. Sarim2022 commented on Dec 4, 2025

    @Sarim2022

    we can add a validation check before creating the array !!

  3. github-actions commented on Dec 5, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  4. added
    state:stale
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:staletype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions