Skip to content

The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.

JavaScript

Hand over bigger files, and climb past a parent that is not an image (#76)

OsintMeThat2cee90e9038d
diff --git a/extension/README.md b/extension/README.md
index 272cf16..1a60ff4 100644
--- a/extension/README.md
+++ b/extension/README.md
@@ -157,7 +157,7 @@ over a map must never end up inside the evidence.
and ordered by the app rather than by this tab: what crosses is one page of a case,
never the case. A video plays in the window, with its own controls.
-Two limits worth knowing. A file has to be **under 24 MB** to be handed over, which
+Two limits worth knowing. A file has to be **under 48 MB** to be handed over, which
is the same ceiling a published thread's attachments answer to. And a video is the
one thing here a site can refuse: an image is decoded and painted on a canvas,
which asks the page's content policy nothing, while a video needs a URL and some
diff --git a/frontend/src/lib/extension.test.js b/frontend/src/lib/extension.test.js
index 24cb42c..bfcbd0b 100644
--- a/frontend/src/lib/extension.test.js
+++ b/frontend/src/lib/extension.test.js
@@ -269,7 +269,7 @@ describe('handle: map-file (a picture for a reference window)', () => {
// through rather than a second copy of the number kept over here
for (const [status, body, message] of [
[401, '', /pairing token rejected/],
- [413, '{"detail":"a handed-over file must be under 24 MB"}', /under 24 MB/],
+ [413, '{"detail":"a handed-over file must be under 48 MB"}', /under 48 MB/],
[404, 'not json at all', /refused that file \(404\)/],
]) {
const fetchImpl = vi.fn(async () => ({ ok: false, status, text: async () => body }));
diff --git a/src/azimut/api/ingest.py b/src/azimut/api/ingest.py
index 00ca699..8a64b7a 100644
--- a/src/azimut/api/ingest.py
+++ b/src/azimut/api/ingest.py
@@ -733,10 +733,12 @@ def mark_grid(body: GridMarksIn) -> dict[str, Any]:
#: a settings file is not something the extension has any business asking for.
HANDOFF_DIRS = ("media", "proofs")
-#: Ceiling for one handed-over file. It travels to the composer as a data URL in a
-#: message, so this is a real limit rather than a policy — and a 40 MB clip refused
-#: here is a clip the analyst attaches by hand, which is what they did before.
-MAX_HANDOFF_BYTES = 24 * 1024 * 1024
+#: Ceiling for one handed-over file. It crosses the extension's worker/page
+#: boundary as base64 in a message, so this is a real limit rather than a policy:
+#: 48 MB of file is ~64 MB of string, held on both sides while the page rebuilds
+#: the file. A clip refused here is a clip the analyst attaches by hand, which is
+#: what they did before.
+MAX_HANDOFF_BYTES = 48 * 1024 * 1024
@router.get("/file", dependencies=[Depends(require_token)])
diff --git a/src/azimut/api/satellite.py b/src/azimut/api/satellite.py
index 27b2db5..52334ae 100644
--- a/src/azimut/api/satellite.py
+++ b/src/azimut/api/satellite.py
@@ -491,7 +491,14 @@ def tile_proxy(provider_id: str, z: int, x: int, y: int) -> Response:
parent = _serve_tile(provider, z - up, x >> up, y >> up)
if parent is None or isinstance(parent, Response):
continue
- image = Image.open(io.BytesIO(parent[0])).convert("RGB")
+ try:
+ image = Image.open(io.BytesIO(parent[0])).convert("RGB")
+ except OSError:
+ # A provider can answer 200 with something that is not an image — an
+ # error document, an empty body. That parent is no use, and the next
+ # level up may well be: climbing on is the same answer as a missing
+ # tile, where a 500 would break the map over a gap it is here to fill.
+ continue
sub = image.width >> up
if sub < 1:
break
diff --git a/tests/test_ingest_api.py b/tests/test_ingest_api.py
index 3ca9439..9c60419 100644
--- a/tests/test_ingest_api.py
+++ b/tests/test_ingest_api.py
@@ -8,6 +8,7 @@ of those walls.
"""
import io
+import os
import struct
import zlib
@@ -429,6 +430,30 @@ def test_the_extension_reads_back_the_attachments_a_thread_carries(client):
assert client.get("/api/ingest/file", params={"case_id": cid, "path": item["path"]}).status_code == 401
+def test_a_file_past_the_ceiling_is_refused_with_the_number_in_it(client, monkeypatch):
+ """The bytes cross the extension as base64 in a message, so there is a size
+ past which handing over is not worth the memory. The extension prints this
+ sentence rather than keeping a second copy of the number, so it states it."""
+ from azimut.api import ingest
+
+ token = _token(client)
+ cid = client.post("/api/cases", json={"name": "Heavy"}).json()["id"]
+ # noise, so the PNG on disk is about as big as the pixels it carries
+ noise = Image.frombytes("RGB", (700, 700), os.urandom(700 * 700 * 3))
+ buf = io.BytesIO()
+ noise.save(buf, format="PNG")
+ item = _upload(client, cid, "clip.png", buf.getvalue())
+ monkeypatch.setattr(ingest, "MAX_HANDOFF_BYTES", 1024 * 1024)
+
+ r = client.get(
+ "/api/ingest/file",
+ params={"case_id": cid, "path": item["path"]},
+ headers={"X-Azimut-Token": token},
+ )
+ assert r.status_code == 413
+ assert r.json()["detail"] == "a handed-over file must be under 1 MB"
+
+
def test_reading_back_reaches_attachments_and_nothing_else(client):
"""A proof PNG and case media are what a post attaches. A sidecar, a spec or a
settings file is not something a composer has any business asking for, and
diff --git a/tests/test_satellite_api.py b/tests/test_satellite_api.py
index ea5b1a0..5e89f6f 100644
--- a/tests/test_satellite_api.py
+++ b/tests/test_satellite_api.py
@@ -573,6 +573,31 @@ def test_tile_proxy_reuses_one_pooled_client(client, monkeypatch):
assert calls["n"] == 3 # three tiles, all served by the one pooled client
+def test_tile_proxy_climbs_past_a_parent_that_is_not_an_image(client, monkeypatch):
+ """Overzoom fills a coverage gap by magnifying a parent tile. A provider can
+ answer 200 with something that is not an image, and that parent is no use —
+ the climb goes on to the next level rather than failing the map with a 500."""
+ import httpx
+
+ from azimut.api import satellite
+
+ def handler(request: httpx.Request) -> httpx.Response:
+ if "/15/" in request.url.path: # the gap that starts the climb
+ return httpx.Response(404)
+ if "/14/" in request.url.path: # 200, and not an image
+ return httpx.Response(
+ 200, content=b"<html>upstream hiccup</html>", headers={"content-type": "image/png"}
+ )
+ return httpx.Response(200, content=_png_bytes(), headers={"content-type": "image/png"})
+
+ monkeypatch.setattr(
+ satellite, "_tile_client", httpx.Client(transport=httpx.MockTransport(handler))
+ )
+ r = client.get("/api/tiles/esri-world-imagery/15/16597/11278")
+ assert r.status_code == 200
+ assert r.headers["X-Azimut-Overzoom"] == "2" # z14 skipped, z13 magnified
+
+
def test_tile_proxy_benches_google_on_a_persistent_403(client, monkeypatch):
"""A 403 that survives the session re-mint names the key (EEA policy,
revoked key) — the basemap must stop being offered, with Google's own
diff --git a/tests/test_updates.py b/tests/test_updates.py
index 80b1d49..8011571 100644
--- a/tests/test_updates.py
+++ b/tests/test_updates.py
@@ -139,7 +139,7 @@ def test_update_endpoint_with_check_queries_github(client, monkeypatch):
# shipped file really changes, set the manifest to the current __version__ and
# record the new digest here (the failing test prints it).
EXTENSION_VERSION = "0.3.0"
-EXTENSION_PAYLOAD = "ba3e0a83a1408aae09997f6893044fd8cc9188d5f41728c481b89094d67967b9"
+EXTENSION_PAYLOAD = "6723a66d5221f4465fb87f3031ca9f53772393efcf9d63b4ca28aa8958917a01"
# The digest itself lives in engine/extinstall.py, because the update button
# compares the same number: what the app ships against what the installed folder