Skip to content

Commit

Permalink
fix: offset in mdat when decrypting (issue #378)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Nov 8, 2024
1 parent 37cd522 commit f696f02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `cmd/mp4ff-encrypt` did not parse command line
- `SeigSampleGroupEntry` calculated skipBytes incorrectly
- `cmd/mp4ff-pslister` did not parse annex B HEVC correctly
- error when decrypting and re-encrypting a segement (issue #378)

### Removed

Expand Down
3 changes: 3 additions & 0 deletions mp4/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ func DecryptFragment(frag *Fragment, di DecryptInfo, key []byte) error {
trun.DataOffset -= int32(nrBytesRemoved)
}
}
if frag.Mdat.StartPos > frag.Moof.StartPos {
frag.Mdat.StartPos -= nrBytesRemoved
}

return nil
}
Expand Down
20 changes: 20 additions & 0 deletions mp4/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ func TestEncryptDecrypt(t *testing.T) {
if !bytes.Equal(rawSeg, decSegBuf.Bytes()) {
t.Errorf("segment not equal after encryption+decryption")
}

// Make a new encryption to check that the decrypted segment is OK
// for re-encryption (Issue #378).

pd2, err := InitProtect(encInit.Init, key, iv, c.scheme, kidUUID, nil)
if err != nil {
t.Error(err)
}
for _, s := range decode.Segments {
for _, f := range s.Fragments {
err := EncryptFragment(f, key, iv, pd2)
if err != nil {
t.Errorf("Error re-encrypting fragment: %v\n", err)
}
}
}
})
}
}
Expand All @@ -238,3 +254,7 @@ func TestDecryptInit(t *testing.T) {
}
}
}

func TestDecryptEncrypt(t *testing.T) {

}

0 comments on commit f696f02

Please sign in to comment.