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
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
from hashlib import sha256
import json
from pathlib import Path, PurePosixPath
from urllib.request import urlopen
from urllib.request import Request, urlopen

BASE_URL = 'https://research.dvidia.org/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/audit/'
INTEGRITY_SHA256 = 'dc7b6091b1c680b9479ea65157c7d553043af688e159463db6174696ad5949fa'
MAX_FILE_BYTES = 25 * 1024 * 1024
MAX_TOTAL_BYTES = 512 * 1024 * 1024
USER_AGENT = 'DVIDIA-Native-Contact-Audit-Downloader/1.0'


def read_url(url, maximum):
with urlopen(url, timeout=60) as response:
request = Request(url, headers={
'User-Agent': USER_AGENT,
'Accept-Encoding': 'identity',
})
with urlopen(request, timeout=60) as response:
payload = response.read(maximum + 1)
if len(payload) > maximum:
raise ValueError('Download exceeded its byte bound.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@
"bytes": 749465
},
"download-audit.py": {
"sha256": "790e826065c91dd3a461f32290aeedd55d9a5efcd4cbde5025378242857a14e5",
"bytes": 3402
"sha256": "fac88c925d06f480de8448149e43d210ce8a96438ca57784f2ba8ec7876ccaf2",
"bytes": 3590
},
"qa.json": {
"sha256": "c9a6120e03d1aea102b4d5aa90bdfb16e0148267672a5650caca9932cef7df3e",
Expand Down
45 changes: 45 additions & 0 deletions scripts/native-contact-audit-publication.test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { spawnSync } from 'node:child_process';
import { createReadStream } from 'node:fs';
import { readFile, readdir } from 'node:fs/promises';
import { resolve } from 'node:path';
Expand All @@ -16,6 +17,50 @@ const PROTOCOL = 'f5ded43bc66dd512e223ffea76ad51897ffea15bb016fa2c29dcd1b4fb6601
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
const json = async path => JSON.parse(await readFile(path));
const close = (a, b, tolerance = 1e-8) => assert.ok(Math.abs(a - b) < tolerance, `${a} != ${b}`);

test('public downloader identifies its client and still enforces byte bounds', () => {
const result = spawnSync('python3', ['-c', String.raw`
from http.server import BaseHTTPRequestHandler, HTTPServer
import runpy
import sys
from threading import Thread

downloader = runpy.run_path(sys.argv[1])
requests = []
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
requests.append((self.path, self.headers.get('User-Agent'), self.headers.get('Accept-Encoding')))
if self.headers.get('User-Agent') != 'DVIDIA-Native-Contact-Audit-Downloader/1.0':
self.send_response(403)
self.end_headers()
return
self.send_response(200)
self.end_headers()
self.wfile.write(b'audit')
def log_message(self, *args):
pass

server = HTTPServer(('127.0.0.1', 0), Handler)
thread = Thread(target=server.serve_forever, daemon=True)
thread.start()
url = f'http://127.0.0.1:{server.server_port}/integrity.json'
try:
assert downloader['read_url'](url, 5) == b'audit'
try:
downloader['read_url'](url, 4)
except ValueError as error:
assert str(error) == 'Download exceeded its byte bound.'
else:
raise AssertionError('Oversized responses must fail.')
assert requests == [('/integrity.json', downloader['USER_AGENT'], 'identity')] * 2
finally:
server.shutdown()
server.server_close()
thread.join()
`, resolve(RUN, 'download-audit.py')], { encoding: 'utf8', timeout: 10_000 });
assert.equal(result.status, 0, result.stderr || result.error?.message);
});

async function files(directory) {
const result = [];
for (const entry of await readdir(directory, { withFileTypes: true })) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
from hashlib import sha256
import json
from pathlib import Path, PurePosixPath
from urllib.request import urlopen
from urllib.request import Request, urlopen

BASE_URL = 'https://research.dvidia.org/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/audit/'
INTEGRITY_SHA256 = 'dc7b6091b1c680b9479ea65157c7d553043af688e159463db6174696ad5949fa'
MAX_FILE_BYTES = 25 * 1024 * 1024
MAX_TOTAL_BYTES = 512 * 1024 * 1024
USER_AGENT = 'DVIDIA-Native-Contact-Audit-Downloader/1.0'


def read_url(url, maximum):
with urlopen(url, timeout=60) as response:
request = Request(url, headers={
'User-Agent': USER_AGENT,
'Accept-Encoding': 'identity',
})
with urlopen(request, timeout=60) as response:
payload = response.read(maximum + 1)
if len(payload) > maximum:
raise ValueError('Download exceeded its byte bound.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@
"bytes": 749465
},
"download-audit.py": {
"sha256": "790e826065c91dd3a461f32290aeedd55d9a5efcd4cbde5025378242857a14e5",
"bytes": 3402
"sha256": "fac88c925d06f480de8448149e43d210ce8a96438ca57784f2ba8ec7876ccaf2",
"bytes": 3590
},
"qa.json": {
"sha256": "c9a6120e03d1aea102b4d5aa90bdfb16e0148267672a5650caca9932cef7df3e",
Expand Down
Loading