Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
id: manifest
env:
UPDATE_BASE_URL: ${{ vars.DASHCAM_OFFLOADER_UPDATE_BASE_URL || 'https://dashcam-offloader-updates.vortexradar.workers.dev' }}
VERSION: 0.1.44
VERSION: 0.1.45
ZIP_NAME: ${{ steps.package.outputs.zip_name }}
ZIP_SHA256: ${{ steps.package.outputs.sha256 }}
SHORT_SHA: ${{ steps.package.outputs.short_sha }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ jobs:
run: node --check workers/feedback/worker.js

- name: Test feedback worker sanitizer
run: node --test workers/feedback/worker.test.mjs
run: node --test workers/feedback/*.test.mjs

- name: Test updates worker
run: node --check workers/updates/worker.js && node --test workers/updates/*.test.mjs

- name: Test scan storage evidence extraction
run: python3 -m unittest discover -s scripts -p 'test_ingest_submitted_scans.py' && python3 -m unittest discover -s scripts -p 'test_scan_storage_rates.py'
Expand Down
5 changes: 3 additions & 2 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,9 @@ must pass strict integrity verification and the app's bundle identifier,
version, and build commit must exactly match the signed manifest. Eject actions
are limited to local removable volumes, never network shares or a manually
chosen subdirectory. Feedback is size-limited while streaming, rate-limited by
a Durable Object, opt-in for ordinary feedback, and excludes user-controlled
filenames, paths, and volume names. Copying computes SHA-256 for each regular
a Durable Object, opt-in for ordinary feedback, and excludes paths and volume
names. Ordinary feedback excludes filenames; the separately reviewed, opt-in
private evidence keeps bounded media basenames (see workers/feedback/README.md). Copying computes SHA-256 for each regular
file after copy and before skipping an existing destination file; a same-size
mismatch is left untouched and reported as a conflict.

Expand Down
2 changes: 1 addition & 1 deletion Sources/DashcamOffloaderApp/CardHealthDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct CardHealthDetailsView: View {

private func fileRow(_ file: CardHealthFileEvidence) -> some View {
HStack(alignment: .top) {
Text("\(file.channel): \(file.relativePath)").font(.system(.caption, design: .monospaced))
Text(verbatim: "\(file.channel): \(file.relativePath)").font(.system(.caption, design: .monospaced))
.frame(maxWidth: .infinity, alignment: .leading)
Button("Reveal") {
guard let url = report.revealableURL(for: file) else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/DashcamOffloaderApp/CardLearningStructure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ enum CardLearningStructure {
name.utf8.count <= 180 && !name.hasPrefix(".") &&
!name.contains("/") && !name.contains("\\") && !name.contains("..") &&
name.range(of: #".+\.(?:mp4|mov|m4v|avi|ts|mts|m2ts|jpg|jpeg|png)$"#, options: [.regularExpression, .caseInsensitive]) != nil &&
name.range(of: #"(?:wifi|password|credential|gps|serial)|[^\s@]+@[^\s@]+\.[^\s@]+|\d{1,3}\.\d{3,}"#, options: [.regularExpression, .caseInsensitive]) == nil &&
name.range(of: #"(?:wifi|password|credential|gps|serial)|[^\s@]+@[^\s@]+\.[^\s@]+|\d{1,3}\.\d{3,}|(?<![\d.])\d{1,3}\.\d+\s*°?\s*[NSEW](?![a-z])|(?<![a-z])[NSEW]\s*\d{1,3}\.\d+"#, options: [.regularExpression, .caseInsensitive]) == nil &&
!name.unicodeScalars.contains {
switch $0.properties.generalCategory {
case .control, .format, .lineSeparator, .paragraphSeparator, .surrogate: return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct CardLearningStructurePreview: View {
Text("\(files.count) sampled camera files with recording type, channel and protection flags").fontWeight(.semibold)
ForEach(Array(files.enumerated()), id: \.offset) { _, file in
VStack(alignment: .leading, spacing: 2) {
Text("\(file.folder)/\(file.filename)").textSelection(.enabled)
Text(verbatim: "\(file.folder)/\(file.filename)").textSelection(.enabled)
Text("\(file.outputCategory) · \(file.channel) · \(file.fileSizeBytes) bytes")
Text("Read-only bits: \(flag(file.filesystemReadOnly)); user/system lock: \(flag(file.userImmutable))/\(flag(file.systemImmutable)); read-only volume: \(flag(file.volumeReadOnly))")
.foregroundStyle(.secondary)
Expand Down
24 changes: 17 additions & 7 deletions Sources/DashcamOffloaderApp/CardScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2031,10 +2031,8 @@ struct CardScanner {
}

func evidenceText(at url: URL) -> String? {
guard let values = try? url.resourceValues(forKeys: [.fileSizeKey]),
let fileSize = values.fileSize,
fileSize <= 1_000_000,
let data = try? Data(contentsOf: url) else {
// The path's size is not the size of what a symbolic link points at.
guard let data = SafeFileRead.data(at: url, maxBytes: 1_000_000) else {
return nil
}

Expand Down Expand Up @@ -2391,7 +2389,7 @@ struct CardScanner {
return nil
}

private func parseTimestamp(groups: [String], format: TimestampFormat) -> Date? {
func parseTimestamp(groups: [String], format: TimestampFormat) -> Date? {
switch format {
case .yyyymmddHhmmss:
// Some patterns have a mode-prefix group before the date
Expand All @@ -2408,8 +2406,20 @@ struct CardScanner {
guard groups.count >= 3 else { return nil }
return parseDate(groups[0] + groups[1] + groups[2], format: "yyyyMMddHHmmss")
case .yyyymmddDashHhmmss:
guard groups.count >= 6 else { return nil }
return parseDate(groups[1] + groups[2] + groups[3] + groups[4] + groups[5] + groups[6], format: "yyyyMMddHHmmss")
// 70mai profiles capture the date/time either as "YYYYMMDD" + "HHMMSS" or as six
// separate fields. Join consecutive all-digit groups that add up to exactly 14 digits.
// (Previously read groups[1...6] behind a count >= 6 guard: never matched the 8+6
// form and skipped the year in the six-field form.)
for start in groups.indices {
var digits = ""
for group in groups[start...] {
guard !group.isEmpty, group.allSatisfy({ $0.isASCII && $0.isNumber }) else { break }
digits += group
if digits.count >= 14 { break }
}
if digits.count == 14 { return parseDate(digits, format: "yyyyMMddHHmmss") }
}
return nil
case .unknown:
return parseTimestampHeuristically(groups: groups)
}
Expand Down
11 changes: 4 additions & 7 deletions Sources/DashcamOffloaderApp/CardScannerParkingInference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,8 @@ extension CardScanner {
}

let configURL = sourceURL.appendingPathComponent("BlackVue/Config/config.ini")
guard let values = try? configURL.resourceValues(forKeys: [.fileSizeKey]),
let fileSize = values.fileSize,
fileSize > 0,
fileSize <= 512 * 1024,
let data = try? Data(contentsOf: configURL),
guard let data = SafeFileRead.data(at: configURL, maxBytes: 512 * 1024),
!data.isEmpty,
let text = String(data: data, encoding: .utf8) else {
return nil
}
Expand Down Expand Up @@ -433,7 +430,7 @@ extension CardScanner {
for item in sortedClips {
if var current = moments.last,
item.timestamp.timeIntervalSince(current.timestamp) <= 3 {
current.totalBytes += item.clip.size
current.totalBytes = current.totalBytes.addingSaturating(item.clip.size)
current.relativePaths.append(item.clip.relativePath)
current.timestamp = min(current.timestamp, item.timestamp)
moments[moments.count - 1] = current
Expand Down Expand Up @@ -648,7 +645,7 @@ extension CardScanner {
}
return grouped.compactMap { key, clips -> (key: Int, timestamp: Date, totalBytes: Int64)? in
guard let timestamp = clips.compactMap(\.timestamp).min() else { return nil }
return (key, timestamp, clips.reduce(Int64(0)) { $0 + $1.size })
return (key, timestamp, clips.reduce(Int64(0)) { $0.addingSaturating($1.size) })
}
.sorted { $0.timestamp < $1.timestamp }
}
Expand Down
9 changes: 8 additions & 1 deletion Sources/DashcamOffloaderApp/CardScannerSourceDiscovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ extension CardScanner {
}


func enumerateFiles(sourceURL: URL) throws -> [URL] {
/// Matches the Electron engine's cap. A real dashcam card holds a few thousand
/// entries; a hostile or mistaken source with millions must not exhaust memory.
static let maxEnumeratedEntries = 500_000

func enumerateFiles(sourceURL: URL, entryLimit: Int = CardScanner.maxEnumeratedEntries) throws -> [URL] {
guard let enumerator = fileManager.enumerator(
at: sourceURL,
includingPropertiesForKeys: [.isRegularFileKey, .fileSizeKey],
Expand All @@ -57,7 +61,10 @@ extension CardScanner {
}

var files: [URL] = []
var visited = 0
for case let fileURL as URL in enumerator {
visited += 1
if visited > entryLimit { break }
let relativePath = fileURL.relativePath(from: sourceURL)
if shouldSkipTraversal(relativePath: relativePath) {
enumerator.skipDescendants()
Expand Down
Loading
Loading