fix: add file magic number verification to diagnose corruption
This commit is contained in:
parent
beaeb3b4c6
commit
0e172e015e
@ -271,7 +271,15 @@ final class PlayerBridge: ObservableObject {
|
||||
let exists = FileManager.default.fileExists(atPath: path)
|
||||
let readable = FileManager.default.isReadableFile(atPath: path)
|
||||
let fileSize = (try? FileManager.default.attributesOfItem(atPath: path)[.size] as? Int) ?? 0
|
||||
diagLog("Local file check: exists=\(exists) readable=\(readable) size=\(fileSize)")
|
||||
// 读前4字节验证文件不是空的/损坏的
|
||||
var magic: UInt32 = 0
|
||||
if let fh = try? FileHandle(forReadingFrom: item.url) {
|
||||
if let d = try? fh.read(upToCount: 4), d.count >= 4 {
|
||||
magic = d.withUnsafeBytes { $0.load(as: UInt32.self) }
|
||||
}
|
||||
try? fh.close()
|
||||
}
|
||||
diagLog("Local file check: exists=\(exists) readable=\(readable) size=\(fileSize) magic=\(String(format:"%08X", magic))")
|
||||
}
|
||||
|
||||
// 先清除旧的 KVO,避免野指针
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user