Add checksum verification for chunk data

develop
trivernis 5 years ago
parent 9f5dfd5fc8
commit 5b82b7c06d

@ -109,14 +109,14 @@ func DecryptDataPng(f *os.File, fout *os.File) {
salt = append(salt, saltChunk.data...)
}
var data []byte
for _, cryptChunk := range png.GetChunksByName(chunkName) {
for i, cryptChunk := range png.GetChunksByName(chunkName) {
if !cryptChunk.Verify() {
log.Fatalf("Corrupted chunk data, chunk #%d", i)
}
data = append(data, cryptChunk.data...)
}
if len(data) > 0 {
data, err = decryptData(data, salt)
if err != nil {
log.Println("\nThe provided password is probably incorrect.")
}
check(err)
_, err = fout.Write(data)
check(err)

@ -30,6 +30,15 @@ func (c *ChunkData) GetRaw() []byte {
return raw
}
// verifies the integrity of the chunks data using crc
func (c *ChunkData) Verify() bool {
var data []byte
data = append(data, []byte(c.name)...)
data = append(data, c.data...)
crc := crc32.ChecksumIEEE(data)
return c.crc == crc
}
type PngData struct {
header []byte
chunks []ChunkData

Loading…
Cancel
Save