The error message tells you all.
==3587== Invalid read of size 4
==3587== at 0x5E27CD0: fwrite (iofwrite.c:41)
==3587== by 0x42D989: main (recover.c:61)
==3587== Address 0x0 is not stack'd, malloc'd or (recently) free'd
buffer
is an array, and the way you use it in
fwrite
is wrong, the value used by
fwrite
is the contain of
buffer
instead of its address.