mirror of
https://github.com/daijro/camoufox.git
synced 2026-11-19 00:07:28 +00:00
* Canvas: reproduce Intel's or AMD's RCPPS/RSQRTPS, chosen per identity Skia's raster pipeline uses x86's estimate instructions for the non-separable and dodge/burn blend modes, perspective and matrix inversion. Intel and AMD implement them with different tables (the same across each vendor's generations and OSes), so canvas readback shows the host's CPU vendor. - cpu-vendor-estimates.patch: pref gfx.skia.cpu_vendor_estimates (0 host, 1 Intel, 2 AMD). When it names the other vendor, rcp_approx and rsqrt_approx in the HSW and SSE paths compute that vendor's bits from a recorded table (SkCpuEstimates.h, SkCpuEstimateTables.h). - browser/tests/cpu-estimates: records each vendor's table and checks the emulation against the native instruction over all 2^32 inputs, and against the other vendor's recorded hashes. - Launcher (Python and TypeScript): cpu_vendor option and cpu:vendor key. The identity derives it from the GPU where only one vendor carries that GPU, and otherwise draws it at Firefox's x86 share (81.4% Intel). A coherence rule warns when the two disagree. Apple Silicon gets none. - Guard cpu-vendor-estimates: stock Firefox 159 hashes from an Intel and an AMD CPU; the build matches each when told to. Audio is not affected: its render splits x86-64 from ARM64, not Intel from AMD. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Opus: encode with the claimed CPU vendor's RCPPS/RSQRTPS; add the CPU probe libopus's PVQ search (celt/x86/vq_sse2.c) uses the same two estimate instructions as Skia, so a WebCodecs, MediaRecorder or WebRTC Opus stream showed the host's vendor: stock Firefox 159 gives one byte stream on Intel and another on AMD. libopus lives in libgkcodecs, which cannot read prefs, so Gecko hands it the table gfx.skia.cpu_vendor_estimates selects (opus_mozilla_set_cpu_estimates) before each encoder is created, and the SSE2 search computes the estimates from it lane by lane. The guard now also encodes one second of Opus and checks it against both vendors' stock streams, on a secure page since WebCodecs needs one. It passes on an AMD host for both vendors. browser/tests/cpu-probe/ is the probe that found it: Math, DOMMatrix, layout, canvas, WebGL, relaxed SIMD, Web Audio and WebCodecs, with stock Firefox 159 results from Intel and AMD on Linux and Windows and from an Apple M4 on macOS and Linux. Intel and AMD differ only in the six estimate-based composite operations and Opus; ARM64 differs in much more, which docs/HOST-PARITY.md now lists as not emulated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * cpu:vendor: a core count only Intel ships implies Intel No AMD x86 CPU since 2015 reports 10, 14, 18, 22 or 28 logical cores: AMD runs one or two threads per core, and its one-thread parts have 2 to 8 cores. Intel's hybrids report all of them (Core Ultra 5 225, 245K, 125H, 155H; i7-14700K). So an identity with such a hardwareConcurrency is drawn Intel, and a cpu_vendor='amd' beside it is reported and repaired. The GPU still decides first: a Radeon APU beside an Intel-only count keeps AMD and is reported, since no vendor matches both. The rule is renamed cpu-vendor-matches-hardware. The counts live in launcher-constants.json (intelOnlyCoreCounts) for both launchers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * cpu {arch, manufacturer}: ARM64 emulation on x86 alongside Intel/AMD The fingerprint's CPU is now { arch: "x86" | "arm", manufacturer } instead of a bare vendor, validated per OS (launcher-constants cpuManufacturers): e.g. Apple + x86 or AMD on macOS is rejected, as is a GPU that never sits beside the claimed CPU. general.cpu_identity = 3 makes an x86 build compute what Firefox's aarch64 build computes: - Skia: the NEON raster pipeline and blend kernels, emulated lane for lane (SkOpts_neonemu, SkNeonEmu.h, SkArmEstimates.h). - Opus: the aarch64 CELT kernels and the NEON inverse MDCT (celt_neonemu.c, celt_tx_neonemu.c, translated from celt_tx_neon.S by scripts/a64toc.py), for decode and encode. - WebAudio / wasm / NaN payloads follow the ARM rules. - libvpx: Firefox configures libvpx realtime-only for linux/arm64 and win/aarch64 (not mac/arm64), which changes WebCodecs VP9 output and rejects quality-mode VP8. The ARM64 configs are now the full encoder and realtime-only is a runtime switch (media.libvpx.realtime_only), so either build can produce either result. libvpx NEON itself is bit-exact with x86. The launchers (Python and TypeScript) set general.cpu_identity and, for an ARM Windows/Linux identity, media.libvpx.realtime_only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ARM64 identity: make the guard's probe reproducible, fail loudly in ffvpx The guard served only the probe's own files, so the two webfonts 404ed and the layout step threw. The probe page draws every input from one seeded stream, so the throw shifted every later key and made wasm relaxed SIMD and the convolver look wrong. The fonts now ship beside the probe (both freely licensed, from Firefox's layout reftests), and the guard fails on any probe step that errors where stock does not. Canvas text is rasterized at the identity's devicePixelRatio, which the launcher draws, so the guard leaves it out; at a ratio of 1 it matches the M4's. FFVPXRuntimeLinker asserts that libmozavutil exports the ARM64 switch instead of skipping it silently. cpu:vendor is kept in properties.json as removed, and the tribal rule, docs and the constants test follow the general.cpu_identity pref. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
170 lines
6.3 KiB
Python
170 lines
6.3 KiB
Python
"""
|
|
Guard: every config key the browser reads must be declared in the schema.
|
|
|
|
Regression guard for the `media:spoof_codecs` gap in PR #562. The C++ side read
|
|
the key via MaskConfig::GetBool("media:spoof_codecs"), but nothing ever added it
|
|
to browser/settings/properties.json, and validate_config() drops any key it does not
|
|
recognise -- printing "Skipping unknown patch media:spoof_codecs" and moving on.
|
|
The documented usage,
|
|
|
|
AsyncCamoufox(config={"media:spoof_codecs": True})
|
|
|
|
therefore did nothing at all: the key never reached the browser, so the feature
|
|
could not be switched on through the supported path.
|
|
|
|
This is the read-but-undeclared direction of a mistake the project has made
|
|
before in the other direction -- canvas:seed (#721) and navigator.maxTouchPoints
|
|
(#696) were both declared in the schema while nothing consumed them. A patch and
|
|
a schema entry are two halves of one change; this test fails the build when only
|
|
one half lands.
|
|
|
|
Run with:
|
|
cd python && python -m pytest tests/test_config_schema.py -v
|
|
"""
|
|
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
PROPERTIES = REPO / "browser" / "settings" / "properties.json"
|
|
|
|
# MaskConfig::GetBool("k") / GetString("k") / GetUint32("k") / HasKey("k") ...
|
|
MASKCONFIG_READ = re.compile(r'MaskConfig::(?:Get|Has)\w*\(\s*"([^"]+)"')
|
|
|
|
# Declared keys the browser never reads, each with the reason it is declared
|
|
# anyway. Everything else in properties.json must be read by a patch or by
|
|
# Juggler: a key nothing reads does nothing, silently.
|
|
NOT_READ_BY_THE_BROWSER = {
|
|
"locale:script": "the launcher joins it with locale:language/region into the UI locale",
|
|
"navigator.doNotTrack": "the launcher applies it as privacy.donottrackheader.enabled (#760)",
|
|
"cpu:arch": "the launcher applies it as general.cpu_identity (cpu-identity.patch)",
|
|
"cpu:manufacturer": "the launcher applies it as general.cpu_identity (cpu-identity.patch)",
|
|
}
|
|
|
|
# How Juggler and the patches name a key: a quoted string literal.
|
|
QUOTED = '"{key}"', "'{key}'"
|
|
|
|
|
|
def _sources():
|
|
for pattern in ("browser/patches/**/*.patch", "browser/additions/**/*"):
|
|
for path in REPO.glob(pattern):
|
|
if path.is_file():
|
|
yield path
|
|
|
|
|
|
def _declared_keys() -> set:
|
|
"""Live keys: an entry marked "removed" is kept only for older libraries."""
|
|
return {
|
|
entry["property"]
|
|
for entry in json.loads(PROPERTIES.read_text())
|
|
if "removed" not in entry
|
|
}
|
|
|
|
|
|
def _removed_keys() -> set:
|
|
return {
|
|
entry["property"]
|
|
for entry in json.loads(PROPERTIES.read_text())
|
|
if "removed" in entry
|
|
}
|
|
|
|
|
|
def _keys_read() -> dict:
|
|
"""Map config key -> sorted list of files that read it."""
|
|
found: dict = {}
|
|
for path in _sources():
|
|
try:
|
|
text = path.read_text(errors="ignore")
|
|
except OSError:
|
|
continue
|
|
for match in MASKCONFIG_READ.finditer(text):
|
|
found.setdefault(match.group(1), set()).add(
|
|
str(path.relative_to(REPO))
|
|
)
|
|
return {k: sorted(v) for k, v in found.items()}
|
|
|
|
|
|
def test_properties_json_is_wellformed():
|
|
entries = json.loads(PROPERTIES.read_text())
|
|
assert entries, "browser/settings/properties.json is empty"
|
|
for entry in entries:
|
|
assert "property" in entry and "type" in entry, f"malformed entry: {entry}"
|
|
|
|
|
|
def test_every_key_the_browser_reads_is_declared():
|
|
declared = _declared_keys()
|
|
read = _keys_read()
|
|
assert read, "found no MaskConfig reads -- the scanner regexp has gone stale"
|
|
|
|
undeclared = {
|
|
key: files
|
|
for key, files in read.items()
|
|
if key not in declared
|
|
}
|
|
if undeclared:
|
|
lines = [
|
|
"config keys are read by the browser but missing from "
|
|
"browser/settings/properties.json,",
|
|
"so validate_config() silently drops them and the feature cannot be "
|
|
"enabled through the Python API:",
|
|
"",
|
|
]
|
|
for key, files in sorted(undeclared.items()):
|
|
lines.append(f" {key}")
|
|
for f in files:
|
|
lines.append(f" read in {f}")
|
|
pytest.fail("\n".join(lines))
|
|
|
|
|
|
def test_every_declared_key_is_read_by_the_browser():
|
|
"""The other direction: canvas:seed (#721) was declared, generated by both
|
|
launchers and sent on every launch for three releases after the patch that
|
|
read it was removed (#528)."""
|
|
text = "".join(path.read_text(errors="ignore") for path in _sources())
|
|
unread = sorted(
|
|
key
|
|
for key in _declared_keys()
|
|
if key not in NOT_READ_BY_THE_BROWSER
|
|
and not any(form.format(key=key) in text for form in QUOTED)
|
|
)
|
|
assert not unread, (
|
|
"browser/settings/properties.json declares keys that no patch or Juggler file "
|
|
f"reads, so setting them does nothing: {unread}. Mark them \"removed\" "
|
|
"(never delete an entry: older libraries reject undeclared keys, #835), "
|
|
"or add them to NOT_READ_BY_THE_BROWSER with the reason they are declared."
|
|
)
|
|
|
|
|
|
def test_removed_keys_are_really_unread():
|
|
"""A key marked removed that the browser reads again is a live key, and the
|
|
launchers would drop it before it reached the browser."""
|
|
text = "".join(path.read_text(errors="ignore") for path in _sources())
|
|
read = sorted(
|
|
key for key in _removed_keys()
|
|
if any(form.format(key=key) in text for form in QUOTED)
|
|
)
|
|
assert not read, f"marked removed in browser/settings/properties.json but read by the browser: {read}"
|
|
|
|
|
|
def test_keys_not_read_by_the_browser_are_really_unread():
|
|
"""An exemption must lapse once the browser starts reading the key."""
|
|
text = "".join(path.read_text(errors="ignore") for path in _sources())
|
|
now_read = [
|
|
key for key in NOT_READ_BY_THE_BROWSER
|
|
if any(form.format(key=key) in text for form in QUOTED)
|
|
]
|
|
assert not now_read, f"remove from NOT_READ_BY_THE_BROWSER, the browser reads them now: {now_read}"
|
|
|
|
|
|
@pytest.mark.parametrize("key", ["media:spoof_codecs"])
|
|
def test_known_previously_missing_keys_stay_declared(key):
|
|
"""Pin the specific keys this guard was written for, so a schema edit that
|
|
drops one fails loudly here rather than only in the general scan above."""
|
|
assert key in _declared_keys(), (
|
|
f"{key} is read by the browser but is not declared in "
|
|
f"browser/settings/properties.json -- see PR #562"
|
|
)
|