### CI Link

https://gradle-enterprise.elastic.co/s/tolzhhuvjvobo/tests/:server:test/org.elasticsearch.gateway.PersistedClusterStateServiceTests/testHandlesShuffledDocuments%20%7Bseed=%5B6281127015198EC1:C2E270963902654%5D%7D?top-execution=1

### Repro line

./gradlew ':server:test' --tests "org.elasticsearch.gateway.PersistedClusterStateServiceTests.testHandlesShuffledDocuments {seed=[6281127015198EC1:C2E270963902654]}" -Dtests.seed=6281127015198EC1 -Dtests.locale=ca -Dtests.timezone=Africa/Asmera -Druntime.java=18

### Does it reproduce?

No

### Applicable branches

master, maybe others

### Failure history

_No response_

### Failure excerpt

```
2> junit.framework.AssertionFailedError: Unexpected exception type, expected CorruptStateException but got java.lang.IndexOutOfBoundsException: Range [4, 4 + -3) out of bounds for length 1 |  
-- | --
  | at __randomizedtesting.SeedInfo.seed([6281127015198EC1:C2E270963902654]:0) |  
  | at org.apache.lucene.tests.util.LuceneTestCase.expectThrows(LuceneTestCase.java:2850) |  
  | at org.apache.lucene.tests.util.LuceneTestCase.expectThrows(LuceneTestCase.java:2831) |  
  | at org.elasticsearch.gateway.PersistedClusterStateServiceTests.testHandlesShuffledDocuments(PersistedClusterStateServiceTests.java:1149) |  
  |   |  
  | Caused by: |  
  | java.lang.IndexOutOfBoundsException: Range [4, 4 + -3) out of bounds for length 1 |  
  | at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100) |  
  | at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromIndexSize(Preconditions.java:118) |  
  | at java.base/jdk.internal.util.Preconditions.checkFromIndexSize(Preconditions.java:397) |  
  | at java.base/java.util.Objects.checkFromIndexSize(Objects.java:411) |  
  | at org.elasticsearch.common.bytes.BytesArray.slice(BytesArray.java:95) |  
  | at org.elasticsearch.common.compress.DeflateCompressor.uncompress(DeflateCompressor.java:208) |  
  | at org.elasticsearch.gateway.PersistedClusterStateService.uncompress(PersistedClusterStateService.java:660) |  
  | at org.elasticsearch.gateway.PersistedClusterStateService.consumeFromType(PersistedClusterStateService.java:622) |  
  | at org.elasticsearch.gateway.PersistedClusterStateService.loadOnDiskState(PersistedClusterStateService.java:551) |  
  | at org.elasticsearch.gateway.PersistedClusterStateService.loadBestOnDiskState(PersistedClusterStateService.java:458) |  
  | at org.elasticsearch.gateway.PersistedClusterStateServiceTests.loadPersistedClusterState(PersistedClusterStateServiceTests.java:1633) |  
  | at org.elasticsearch.gateway.PersistedClusterStateServiceTests.lambda$testHandlesShuffledDocuments$30(PersistedClusterStateServiceTests.java:1149) |  
  | at org.apache.lucene.tests.util.LuceneTestCase._expectThrows(LuceneTestCase.java:3003) |  
  | at org.apache.lucene.tests.util.LuceneTestCase.expectThrows(LuceneTestCase.java:2840) |  
  | ... 2 more
```

I haven't been able to get a reliable reproduction line, but usually running the test 10,000 times seems to provoke it:

```
for i in {0..100}; do ./gradlew ':server:test' -Dtests.iters=100 --tests "org.elasticsearch.gateway.PersistedClusterStateServiceTests.testHandlesShuffledDocuments"; done
```
server/src/test/java/org/elasticsearch/common/compress/DeflateCompressTests.java
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */
package org.elasticsearch.common.compress;
import org.apache.lucene.tests.util.LineFileDocs;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.test.ESTestCase;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.zip.ZipException;
/**
 * Test streaming compression (e.g. used for recovery)
 */
public class DeflateCompressTests extends ESTestCase {