π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[space][web] Limit image diagnostics to a 64 KB prefix
Anand Baburajand4efeb8264a3
diff --git a/web/apps/space/src/utils/post-image-diagnostics.ts b/web/apps/space/src/utils/post-image-diagnostics.tsindex 2de5f38161..69231f4db5 100644--- a/web/apps/space/src/utils/post-image-diagnostics.ts+++ b/web/apps/space/src/utils/post-image-diagnostics.ts@@ -18,12 +18,12 @@ export const logSpaceImageReadCheck = async (const { requestId, attempt, item } = context;const startedAt = performance.now();logToDisk(- `[info] Space image read check ${JSON.stringify({ requestId, attempt, item, outcome: "started" })}`,+ `[info] Space image prefix read check ${JSON.stringify({ requestId, attempt, item, outcome: "started" })}`,);- let outcome = "readable";+ let outcome = "prefix-readable";let error: string | undefined;try {- await file.arrayBuffer();+ await file.slice(0, 64 * 1024).arrayBuffer();} catch (cause) {outcome = "failed";const name = cause instanceof Error ? cause.name : "Unknown";@@ -40,6 +40,6 @@ export const logSpaceImageReadCheck = async (: "Unknown";}logToDisk(- `[info] Space image read check ${JSON.stringify({ requestId, attempt, item, outcome, error, elapsedMs: Math.round(performance.now() - startedAt) })}`,+ `[info] Space image prefix read check ${JSON.stringify({ requestId, attempt, item, outcome, error, elapsedMs: Math.round(performance.now() - startedAt) })}`,);};diff --git a/web/apps/space/tests/post-image-diagnostics.test.ts b/web/apps/space/tests/post-image-diagnostics.test.tsindex 82be89c191..e094586fb0 100644--- a/web/apps/space/tests/post-image-diagnostics.test.ts+++ b/web/apps/space/tests/post-image-diagnostics.test.ts@@ -25,7 +25,7 @@ test("checks a failed image once and logs progress while the read is pending", aconst file = new File(["PRIVATE_CONTENT"], "PRIVATE_FILENAME.jpg");const pendingRead = Promise.withResolvers<ArrayBuffer>();const read = vi- .spyOn(file, "arrayBuffer")+ .spyOn(Blob.prototype, "arrayBuffer").mockReturnValue(pendingRead.promise);vi.spyOn(performance, "now").mockReturnValue(100);@@ -40,10 +40,26 @@ test("checks a failed image once and logs progress while the read is pending", aexpect(entries()).toEqual([{ ...context, outcome: "started" },- { ...context, outcome: "readable", elapsedMs: 50 },+ { ...context, outcome: "prefix-readable", elapsedMs: 50 },]);});+test.each([1024, 128 * 1024])(+ "reads at most 64 KB from a %i-byte file",+ async (size) => {+ const file = new File([new Uint8Array(size)], "photo.jpg");+ const read = vi.spyOn(Blob.prototype, "arrayBuffer");++ await logSpaceImageReadCheck(file, decodeError, context);++ expect(read).toHaveBeenCalledOnce();+ await expect(read.mock.results[0]!.value).resolves.toHaveProperty(+ "byteLength",+ Math.min(size, 64 * 1024),+ );+ },+);+test.each(["NotReadableError", "PRIVATE_NAME"])("logs a safe read error category for %s without private data",async (name) => {@@ -53,7 +69,7 @@ test.each(["NotReadableError", "PRIVATE_NAME"])(});const error = new DOMException("PRIVATE_PATH", name);error.stack = "PRIVATE_STACK";- vi.spyOn(file, "arrayBuffer").mockRejectedValue(error);+ vi.spyOn(Blob.prototype, "arrayBuffer").mockRejectedValue(error);vi.spyOn(performance, "now").mockReturnValue(100);await logSpaceImageReadCheck(file, decodeError, context);@@ -75,7 +91,7 @@ test.each([new Error("Could not encode image"), "PRIVATE_ERROR"])("does not read or log for other preparation failures: %s",async (error) => {const file = new File(["photo"], "photo.jpg");- const read = vi.spyOn(file, "arrayBuffer");+ const read = vi.spyOn(Blob.prototype, "arrayBuffer");await logSpaceImageReadCheck(file, error, context);