static boolean checkChunkSane(Chunk chunk)
    {
        if (chunk == null)
        {
            // If the chunk does not exist, it can not be wrong...
            return true;
        }

        if (chunk.start + chunk.length > chunk.bytes.length)
        {
            return false;
        }

        if (chunk.start < 4)
        {
            return false;
        }

        // We must include the chunk type in the CRC calculation
        int ourCRC = crc(chunk.bytes, chunk.start - 4, chunk.length + 4);
        if (ourCRC != chunk.crc)
        {
            LOG.error(String.format("Invalid CRC %08X on chunk %08X, expected %08X.", ourCRC,
                    chunk.chunkType, chunk.crc));
            return false;
        }
        return true;
    }
@Test
    void testChunkSane()
    {
        PNGConverter.Chunk chunk = new PNGConverter.Chunk();
        assertTrue(PNGConverter.checkChunkSane(null));
        chunk.bytes = "IHDRsomedummyvaluesDummyValuesAtEnd".getBytes();
        chunk.length = 19;
        assertEquals(35, chunk.bytes.length);

        assertEquals("IHDRsomedummyvalues", new String(chunk.getData()));

        assertFalse(PNGConverter.checkChunkSane(chunk));
        chunk.start = 4;
        assertEquals("somedummyvaluesDumm", new String(chunk.getData()));
        assertFalse(PNGConverter.checkChunkSane(chunk));
        chunk.crc = -1729802258;
        assertTrue(PNGConverter.checkChunkSane(chunk));
        chunk.start = 6;
        assertFalse(PNGConverter.checkChunkSane(chunk));
        chunk.length = 60;
        assertFalse(PNGConverter.checkChunkSane(chunk));
    }