Correct 4 bytes out of 65K to match a crc32 checksum I have a corrupted png image. I checked and the crc32 checksum of the first chunk (size ~65k) does not match with the one I get. I am sure of this.

Also, I have identified the 4 bytes that have the wrong value. I am sure of this.

My question: Is there an efficient way to calculate the values of these 4 bytes, in order to match the required crc32 checksum?

I made a program in C to brute force the values, using this CRC32 function

#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdint.h&gt;
#include &lt;string.h&gt;

// The CRC32 function
uint32_t crc32(uint32_t crc, const void *buf, size_t SIZE_CHUNK);

// The size of the corrupted chunk (TYPE+DATA)
uint32_t SIZE_CHUNK = 65449;

// The CRC32 that has to be matched
uint32_t GOOD_CRC32 = 2784191201;

// The offset of the 4 corrupted bytes
uint32_t OFF[4] = {20121, 20467, 20742, 20893};

int main() {
        uint8_t *buf = (uint8_t *)calloc(SIZE_CHUNK, sizeof(uint8_t));
        uint32_t i, j, k, l, crc = 0;
        FILE *fp;

        fp = fopen("corrupted.png", "r+");
        // Offset to the first `IDAT` chunk of the png file
        fseek(fp, 87, SEEK_SET);
        // We fill `but` with the TYPE+DATA fields of the chunk
        fread(buf, sizeof(uint8_t), SIZE_CHUNK, fp);

        // Bruteforce...
        for (i=0; i&lt;256; i++) {
                buf[OFF[0]] = i;
                for (j=0; j&lt;256; j++) {
                        buf[OFF[1]] = j;
                        for (k=0; k&lt;256; k++) {
                                buf[OFF[2]] = k;
                                for (l=0; l&lt;256; l++) {
                                        buf[OFF[3]] = l;
                                        crc = crc32(0, buf, SIZE_CHUNK);
                                        if (crc == GOOD_CRC32)
                                                printf("Values found! i=%d j=%d k=%d l=%d\n", i,j,k,l);
                                }
                        }
                }
        }
        free(buf);
        fclose(fp);
}


However, this is very slow. If it doesn't speed up, it may take several days. It might be due to the size of the chunk (~65Kb).

I thought about pre-compute the CRC (the part from 0 to OFF[0]-1), but it would still be too long.


  Info:  
  
  The exact size of the chunk is 65449. The corrupted bytes positions
  are between 20k-21k.
Disclaimer: It is not a review, and I am wild guessing.

The DrDobbs article outlines how the partial CRC could be recombined. I recommend to precompute CRCs of all fixed parts of the chunk, and let the GPU handle the rest. GPUs are notoriously good in number crunching, and you have at least 16K+ truly parallel cores on your graphics card. It is \$2^{18}\$ search space per core. Seems feasible.