indygreg / apple-platform-rs

Rust crates supporting Apple platform development
568 stars 40 forks source link

cpio-archive: fix header and file padding of newc #68

Closed johnmave126 closed 1 year ago

johnmave126 commented 1 year ago

The previous implementation of cpio-archive of newc format contains two problems:

  1. The whole header should be aligned to 4-byte boundary, including the magic, but the implementation only aligns the entry name to 4-byte boundary.
  2. When calculating the amount to pad, the implementation uses (length % 4) as the number of bytes to pad, but it should be (4 - (length % 4)) % 4.

This commit fixes these two problems, and replaces vec! by an on-stack array as the padding scratch space to avoid unnecessary heap allocation.