contentauth / c2pa-rs

Rust SDK for the core C2PA (Coalition for Content Provenance and Authenticity) specification
Other
99 stars 42 forks source link

pad_cose_sig() not correctly calculating padding size #492

Open vancejc-mt opened 1 week ago

vancejc-mt commented 1 week ago

If the reserve size returned by AsyncSigner::reserve_size() is fairly close (but not exact) to the size of the Cose_Sign1 structure which c2pa-rs generates, we're seeing CoseSigboxTooSmall errors be returned.

The behavior of this is somewhat weird, and I believe it's because the padding calculation (let mut target_guess = end_size - cur_size - PAD_OFFSET) doesn't accurately account for the size which the header itself will take up once it's DER encoded. Thus it calculates a pad which is too large which then causes the reserve size to be overwhelmed.

I don't believe this should ever be the case - if the reserve size is larger than the size of the eventual Cose_Sign1 structure, this should succeed.

Maybe this is an understanding on my part? But to get this to work correctly, we're having to add in overly big reserve sizes to avoid the issue.