From bf96273ea8558efdf0e36c860bcfa101e99e875b Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 31 Jul 2018 18:56:18 +0300 Subject: [PATCH] [TAR] Apply base-256 encoding to negative values as well --- Sources/TAR/ByteReader+Tar.swift | 4 +--- Sources/TAR/TarEntryInfo.swift | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/TAR/ByteReader+Tar.swift b/Sources/TAR/ByteReader+Tar.swift index 0f1d395b..ddb3f07f 100644 --- a/Sources/TAR/ByteReader+Tar.swift +++ b/Sources/TAR/ByteReader+Tar.swift @@ -22,9 +22,7 @@ extension ByteReader { */ func tarCString(maxLength: Int) -> String { var buffer = self.bytes(count: maxLength) - guard !buffer.isEmpty - else { return "" } - if buffer.last! != 0 { + if buffer.last != 0 { buffer.append(0) } return buffer.withUnsafeBufferPointer { String(cString: $0.baseAddress!) } diff --git a/Sources/TAR/TarEntryInfo.swift b/Sources/TAR/TarEntryInfo.swift index 61b00df7..17560102 100644 --- a/Sources/TAR/TarEntryInfo.swift +++ b/Sources/TAR/TarEntryInfo.swift @@ -361,7 +361,7 @@ fileprivate extension Data { } let maxOctalValue = (1 << (maxLength * 3)) - 1 - guard value > maxOctalValue else { + guard value > maxOctalValue || value < 0 else { // Normal octal encoding. self.append(String(value, radix: 8).data(using: .utf8)!.zeroPad(maxLength)) return