Sync source edition with VCC Plus 3.7.0 build 63
This commit is contained in:
1 parent
c652a5276d
commit
b2ecec4d87
86 files changed
+10519
-472
No files matched your search
@@ -122,10 +122,10 @@ actor SoftwareLibraryArtworkCache {
|
||||
}
|
||||
|
||||
static func canDisplay(_ asset: SoftwareLibraryAsset) -> Bool {
|
||||
guard let url = asset.thumbnailURL, accepts(url),
|
||||
guard let url = asset.thumbnailURL, accepts(url) || (asset.matchStatus == "personal" && url.isFileURL),
|
||||
let checksum = asset.thumbnailSHA256, checksum.count == 64,
|
||||
checksum.allSatisfy({ $0.isHexDigit }),
|
||||
let size = asset.thumbnailByteSize, size > 0, size <= maximumThumbnailBytes else { return false }
|
||||
let size = asset.thumbnailByteSize, size > 0, size <= (asset.matchStatus == "personal" ? Int64(maximumSourceBytes) : Int64(maximumThumbnailBytes)) else { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -165,6 +165,11 @@ actor SoftwareLibraryArtworkCache {
|
||||
}
|
||||
|
||||
func thumbnail(for asset: SoftwareLibraryAsset, directory: URL) async throws -> Data {
|
||||
if asset.matchStatus == "personal", let url = asset.thumbnailURL, url.isFileURL {
|
||||
try SoftwareLibraryLocalAsset.validate(asset, url: url, maximumBytes: Int(Self.maximumSourceBytes))
|
||||
return try Self.downsample(Data(contentsOf: url), expectedSHA256: asset.thumbnailSHA256)
|
||||
}
|
||||
|
||||
try Task.checkCancellation()
|
||||
guard Self.canDisplay(asset), let url = asset.thumbnailURL,
|
||||
let fingerprint = asset.thumbnailSHA256 else { throw Failure.unsupported }
|
||||
@@ -241,3 +246,35 @@ private final class LibraryArtworkRedirects: NSObject, URLSessionTaskDelegate {
|
||||
completionHandler(request.url.map(SoftwareLibraryArtworkCache.accepts) == true ? request : nil)
|
||||
}
|
||||
}
|
||||
|
||||
/// Local assets are accepted only from a namespaced private entry's Assets tree.
|
||||
/// The public catalog/cache URL allowlists remain unchanged.
|
||||
enum SoftwareLibraryLocalAsset {
|
||||
static func validate(_ asset: SoftwareLibraryAsset, url: URL, maximumBytes: Int) throws {
|
||||
guard asset.matchStatus == "personal", url.isFileURL, url.host == nil || url.host == "localhost",
|
||||
url.query == nil, url.fragment == nil, let expected = asset.sha256,
|
||||
expected.count == 64, expected.allSatisfy(\.isHexDigit), let size = asset.byteSize,
|
||||
size > 0, size <= maximumBytes else { throw SoftwareLibraryManualCache.Failure.unavailable }
|
||||
let parts = url.standardizedFileURL.pathComponents
|
||||
guard let index = parts.lastIndex(of: "PersonalLibrary"), parts.count > index + 3,
|
||||
UUID(uuidString: parts[index + 1]) != nil, parts[index + 2] == "Assets",
|
||||
asset.id.hasPrefix("personal:" + parts[index + 1].lowercased() + ":asset:") else { throw SoftwareLibraryManualCache.Failure.unavailable }
|
||||
// System parent aliases such as /var are legitimate. The private
|
||||
// library root and every component beneath it must be nonsymlink.
|
||||
var checked = URL(fileURLWithPath: NSString.path(withComponents: Array(parts.prefix(index))), isDirectory: true)
|
||||
for part in parts.dropFirst(index) {
|
||||
checked.appendPathComponent(part)
|
||||
guard try checked.resourceValues(forKeys: [.isSymbolicLinkKey]).isSymbolicLink != true else { throw SoftwareLibraryManualCache.Failure.unavailable }
|
||||
}
|
||||
let values = try url.resourceValues(forKeys: [.isRegularFileKey, .fileSizeKey])
|
||||
guard values.isRegularFile == true, values.fileSize == Int(size) else { throw SoftwareLibraryManualCache.Failure.changed }
|
||||
let handle = try FileHandle(forReadingFrom: url); defer { try? handle.close() }
|
||||
var hash = SHA256(), count = 0
|
||||
while let block = try handle.read(upToCount: 1024 * 1024), !block.isEmpty {
|
||||
try Task.checkCancellation(); count += block.count
|
||||
guard count <= maximumBytes else { throw SoftwareLibraryManualCache.Failure.changed }
|
||||
hash.update(data: block)
|
||||
}
|
||||
guard count == Int(size), hash.finalize().map({ String(format: "%02x", $0) }).joined() == expected.lowercased() else { throw SoftwareLibraryManualCache.Failure.changed }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user