Fix critical issues from PR #681 review

Critical fixes:
- BinaryProtocol: Return nil for unknown versions (prevents buffer underflows)
- Add BinaryProtocol.Offsets struct to centralize magic numbers
- Replace magic offset calculations with named constants

Security/Privacy:
- FileAttachmentView: Use url.lastPathComponent instead of url.path
  (prevents exposing full system paths)

Documentation:
- Fix compression algorithm documentation (zlib, not LZ4)

All tests passing.
This commit is contained in:
jack
2025-10-15 17:37:19 +01:00
committed by islam
parent 5beff8b4dc
commit f0ca1b27c2
5 changed files with 26 additions and 15 deletions
@@ -68,7 +68,10 @@ struct BinaryProtocolTests {
let encodedData = try #require(BinaryProtocol.encode(packet), "Failed to encode packet with large payload")
// The encoded size should be smaller than uncompressed due to compression
let headerSize = BinaryProtocol.headerSize(for: packet.version)
guard let headerSize = BinaryProtocol.headerSize(for: packet.version) else {
XCTFail("Invalid version")
return
}
let uncompressedSize = headerSize + BinaryProtocol.senderIDSize + largePayload.count
#expect(encodedData.count < uncompressedSize, "Compressed packet should be smaller than uncompressed form")