| | @@ -372,6 +372,31 @@ fn local_sizes(size: u32, compressed: u32, extra: Option<&[u8]>) -> Result<(u64, |
| 372 | 372 | Ok((size as u64, compressed as u64)) |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | +추가: fn descriptor_size( |
| 376 | +추가: bytes: &[u8], |
| 377 | +추가: crc: u32, |
| 378 | +추가: compressed: u64, |
| 379 | +추가: size: u64, |
| 380 | +추가: wide_required: bool, |
| 381 | +추가: ) -> Result<usize> { |
| 382 | +추가: // 일반 크기 헤더와 64비트 디스크립터를 함께 기록하는 도구도 있음. |
| 383 | +추가: if bytes.len() >= 20 |
| 384 | +추가: && u32at(bytes, 0) == crc |
| 385 | +추가: && u64at(bytes, 4) == compressed |
| 386 | +추가: && u64at(bytes, 12) == size |
| 387 | +추가: { |
| 388 | +추가: return Ok(20); |
| 389 | +추가: } |
| 390 | +추가: if !wide_required |
| 391 | +추가: && bytes.len() >= 12 |
| 392 | +추가: && u32at(bytes, 0) == crc |
| 393 | +추가: && u32at(bytes, 4) as u64 == compressed |
| 394 | +추가: && u32at(bytes, 8) as u64 == size |
| 395 | +추가: { |
| 396 | +추가: return Ok(12); |
| 397 | +추가: } |
| 398 | +추가: Err(ErrorCode::Integrity) |
| 399 | +추가: } |
| 375 | 400 | fn zip( |
| 376 | 401 | source: &mut File, |
| 377 | 402 | len: u64, |
| | @@ -579,19 +604,9 @@ fn zip( |
| 579 | 604 | if signature == b"PK\x07\x08" { |
| 580 | 605 | stop = add(stop, 4)?; |
| 581 | 606 | } |
| 582 | | -삭제: if add(stop, descriptor_len)? > central { |
| 583 | | -삭제: return Err(ErrorCode::Integrity); |
| 584 | | -삭제: } |
| 585 | | -삭제: let d = bytes(source, stop, descriptor_len as usize)?; |
| 586 | | -삭제: let (pc, ps) = if size_zip64 { |
| 587 | | -삭제: (u64at(&d, 4), u64at(&d, 12)) |
| 588 | | -삭제: } else { |
| 589 | | -삭제: (u32at(&d, 4) as u64, u32at(&d, 8) as u64) |
| 590 | | -삭제: }; |
| 591 | | -삭제: if u32at(&d, 0) != crc || pc != compressed || ps != size { |
| 592 | | -삭제: return Err(ErrorCode::Integrity); |
| 593 | | -삭제: } |
| 594 | | -삭제: stop += descriptor_len; |
| 607 | +추가: let d = bytes(source, stop, (central - stop).min(20) as usize)?; |
| 608 | +추가: let descriptor_len = descriptor_size(&d, crc, compressed, size, size_zip64)?; |
| 609 | +추가: stop = add(stop, descriptor_len as u64)?; |
| 595 | 610 | } |
| 596 | 611 | spans.push((local, stop)); |
| 597 | 612 | packed.push(Packed { |