Commit graph

3131 commits

Author SHA1 Message Date
Kelsi
63dbfe74b0 fix(wom): cap top-level vert/index/tex counts on save
Top-level WOM save was writing raw model.vertices/.indices/.texturePaths
sizes; load enforces 1M / 4M / 1024 limits. A pathological model would
emit a header rejected on load, leaking the rest of the file body.

Cap each count at the load limit and iterate the WOM1 vertex block +
texture-path block by index so the body matches the header.
2026-05-06 09:16:43 -07:00
Kelsi
b85734e311 fix(wom): cap WOM3 batch count at load limit (4096) on save
Same per-section cap pattern. The loader caps batchCount at 4096;
save iterated all validBatches without checking. A model with
>4096 batches would write a header rejected on round-trip.
2026-05-06 09:15:02 -07:00
Kelsi
0547ab882a fix(wob): cap per-portal vertex count on save to match load limit
Same per-section cap pattern. Real portals carry 4-12 verts; the
load enforces 4096 max. Save previously wrote raw size() so a
huge portal would write a header the loader rejects.
2026-05-06 09:13:34 -07:00
Kelsi
30d1acbeee fix(wob): cap per-group vertex/index/texture counts on save
Per-group counts were uncapped on save while load enforced 1M
vertices, 4M indices, 1024 texture paths. A single huge group
exceeded any cap would write a header the loader rejects, leaking
the rest of the file body into a misread chain.

Cap counts at the load limits and iterate the texture-path block
by index so the body matches the header on round-trip.
2026-05-06 09:12:17 -07:00
Kelsi
2cd69d677a fix(wob): cap group/portal/doodad header counts on save
WoB load enforces 4096 groups / 8192 portals / 65536 doodads. Save
previously wrote raw size() and iterated all entries — a build
exceeding any cap would be rejected wholesale on round-trip.

Cap each count at the load limit and use indexed loops so the
written body matches the header count even if the in-memory data
goes over.
2026-05-06 09:10:14 -07:00
Kelsi
c5008750ce fix(woc): cap triangle count and clamp tile coords on save
WOC load caps tris at 2M and clamps tile coords to 0..63. Save
previously wrote raw size() and tileX/Y — a >2M-tri collision
would be silently rejected on round-trip, and OOR tile coords
would log a warning every reload. Cap at save and reuse the
load-side clamp so the on-disk file is round-trip clean.
2026-05-06 09:08:07 -07:00
Kelsi
241722feaa fix(wom): cap bone/animation counts at save (matches load limits)
WOM load caps bones at 512 and animations at 1024. Save previously
wrote raw size() and iterated all entries — a model with >512 bones
would write fine but truncate on round-trip, and the post-truncation
keyframe data would be misread as the next animation.

Cap both counts at save and iterate using the capped value so the
per-bone keyframe block stays aligned with what load expects.
2026-05-06 09:06:46 -07:00
Kelsi
4a534c24e8 fix(wob): cap material count at 256 on save (matches load limit)
Save previously wrote raw materials.size() as the count, then iterated
all materials. Load caps at 256, so a build with >256 materials would
write fine but truncate on round-trip and the post-truncation block
would be misread as the next group's data. Cap at save and only write
the first 256.
2026-05-06 09:04:18 -07:00
Kelsi
39f4a433ff fix(camera): NaN-safe getRight/getUp when forward ~= world up
If forward is parallel to (0,0,1) — camera staring straight up or
down — the cross product is zero and glm::normalize returned NaN.
That NaN flowed into glm::lookAt and produced a NaN view matrix.

The editor camera clamps pitch to +/-89 so it doesn't trigger,
but other call sites or scripted test paths could construct a
Camera at +/-90 and immediately blow up. Length-check the cross
and fall back to world +X / +Z.
2026-05-06 08:55:49 -07:00
Kelsi
cfd257aa78 fix(m2): skip NaN vertices when computing tight model bounds
glm::min/max on NaN is implementation-defined, so a single bad
vertex would propagate NaN into the camera-occlusion and culling
AABB used by the runtime. WOM/M2 loaders already scrub but defense
in depth catches anything they miss. Falls back to a unit box if
every vertex is bad.
2026-05-06 08:51:31 -07:00
Kelsi
61fb486b9e fix(m2): degenerate-normal guard during walkable-floor raycast
The matrix-transformed normal could be near-zero if the M2 instance
has a degenerate scale; glm::normalize then returns NaN that
contaminates the slope check (NaN < 0.35 is false → no early-out)
and bestNormalZ goes NaN, breaking the walkable-floor heuristic.

Length-check the transformed normal and fall back to the (0,0,1)
flat default — same pattern as the WMO renderer.
2026-05-06 08:49:26 -07:00
Kelsi
ae20fbf621 fix(wmo): degenerate-normal guard during tangent generation
A WMO vertex with zero-length or NaN normal would produce a NaN
normalized normal, contaminating the Gram-Schmidt tangent for the
whole vertex and producing visibly broken normal mapping for the
affected face. Length-check before normalize and fall back to
(0,0,1) when degenerate.
2026-05-06 08:47:31 -07:00
Kelsi
86c544b841 fix(wmo): degenerate-portal guard during portal plane build
A portal whose first three vertices are coincident or collinear
produces a zero cross product and glm::normalize returns NaN. The
NaN propagates into the portal-frustum cull (every interior group
either always-visible or never-visible depending on plane orientation).

Use the same length-check pattern as the editor's spline/path code:
zero cross → fall back to (0,0,1) up-axis.
2026-05-06 08:46:20 -07:00
Kelsi
b7e3266c7a fix(m2): NaN guards on createInstanceWithMatrix boundary
Mirrors the createInstance guard. position drives the dedup hash
key (std::round of NaN is implementation-defined) and the matrix
flows into the GPU UBO.
2026-05-06 08:36:11 -07:00
Kelsi
61116e94a5 fix(m2): NaN guards on setInstancePosition and setInstanceTransform
Same boundary-rejection pattern as createInstance. NaN in either
function would corrupt the spatial grid (stale cells pointing at
NaN-bounded instances) and the GPU model-matrix UBO.
2026-05-06 08:34:53 -07:00
Kelsi
f96ea12fe7 fix(m2): reject NaN inputs at M2Renderer::createInstance
Even with all the upstream guards I've been adding, internal callers
or addon-style scripted spawns could pass NaN. Reject at the API
boundary so we never hash-key with NaN coords (std::round of NaN
is implementation-defined) or push a NaN instance into the model-
matrix uniform buffer (GPU crash / origin render).
2026-05-06 08:32:48 -07:00
Kelsi
6657f08252 fix(wob): sanitize portal vertices/group indices on load and save
Three issues addressed:
- NaN portal vertices break the WMO portal-frustum cull, defeating
  the indoor optimization and forcing the whole interior to draw.
- Out-of-range portal.groupA/groupB indices walk past wmo.groups
  during cull; clamp to -1 (invalid) on load.
- Symmetric save-side scrub so we don't persist bad in-memory data.
2026-05-06 08:15:31 -07:00
Kelsi
44777c7d58 fix(mesh): clamp NaN terrain heights to 0 in vertex generation
WHM load already scrubs, but mid-edit terrain can briefly carry
NaN before stitchEdges runs. A single NaN vertex propagates into
normal computations and the chunk's frustum cull, crashing both.
2026-05-06 08:11:43 -07:00
Kelsi
778f4aca3e fix(wob): warn + clamp uint32 indices on WMO conversion
WoB allows uint32 indices but WMO format is uint16. The previous
static_cast would silently wrap a >65k index into a wrong-but-
valid value — producing visible mis-stitched triangles in the
renderer. Now log a warning once per group and clamp to 0
(degenerate triangle) so the bug is visible.
2026-05-06 07:32:07 -07:00
Kelsi
9cb8b160ef fix(wob): clamp out-of-range indices at save time
Symmetric with the load-side index clamp.
2026-05-06 07:29:29 -07:00
Kelsi
dbb3be86f2 fix(wom): clamp out-of-range indices at save time
Symmetric with the load-side index clamp. A WoM whose indices
reference past the vertex buffer would crash the GPU vertex shader;
the save side now clamps to 0 (degenerate triangle) so the file
matches what the load guard would produce.
2026-05-06 07:28:31 -07:00
Kelsi
a0895fabdf fix(wom): drop invalid batches at save time
Symmetric with the load-side validation. A WOM3 batch whose
indexStart+indexCount exceeds the index buffer, or whose texture
index points past the texture array, would otherwise emit an
invalid file that the load-time guard then has to drop.

Filter at save instead so the on-disk file stays compact and
self-consistent.
2026-05-06 07:27:33 -07:00
Kelsi
c00bfab1a5 fix(wom): scrub NaN bone pivots and clamp parent indices at save time
Symmetric with the existing load-side guards. A bone with a NaN
pivot poisons its child bones' world matrices; an out-of-range
parent index would walk past the bones array during evaluation.
2026-05-06 07:26:26 -07:00
Kelsi
3b1fad7be9 fix(wob): scrub NaN/inf group vertices at save time
Symmetric scrub on the WoB save path matching the existing load
guard. A manually-constructed WoweeBuilding with NaN vertices
would otherwise persist them and force the load-time scrub to
re-clean the same data on every reload.
2026-05-06 07:24:51 -07:00
Kelsi
6347e78d72 fix(wom): scrub NaN/inf bone keyframes at save time
The load side already scrubs keyframe translation/rotation/scale
floats, but fromM2 → save → load is the typical path: a corrupt
M2 source would write NaN keyframes that the load-time guard would
have to clean up on every subsequent load. Symmetric scrub here
ensures the file is clean from the start.

movingSpeed also defaults to 0 if non-finite (matches load).
2026-05-06 07:23:35 -07:00
Kelsi
d1f347a9c1 fix(wob): sanitize doodad transform during fromWMO conversion
A WMO with a NaN doodad quaternion would produce NaN euler angles
through glm::eulerAngles() and persist them into the WoB. Identity
quaternion fallback for a non-finite source, plus NaN scrub on
position/rotation/scale separately so the converted WOB is always
load-safe.
2026-05-06 07:13:49 -07:00
Kelsi
ed749b9afa fix(wot): clamp liquid type to known range on load
WoW liquid types are 0=water/1=ocean/2=magma/3=slime. A user-edited
WOT could carry an out-of-range value that the editor renderer
silently maps to plain water but the server treats as undefined.
2026-05-06 07:09:48 -07:00
Kelsi
1c1250a37c fix(wot): scrub NaN water height on load
A WOT water entry with non-finite height would push NaN through
the water mesh builder and produce a degenerate Vulkan draw
(invisible water at best, GPU hang at worst).
2026-05-06 07:08:50 -07:00
Kelsi
b8e2d08b17 fix(wob): scrub NaN/inf doodad transforms at save time
Same scrub now applied symmetrically on the save side so a
corrupted in-memory doodad transform can't be persisted into a
WOB and then have to be cleaned up on every subsequent load.
2026-05-06 07:07:21 -07:00
Kelsi
5d78cbb81d fix(wob): scrub NaN/inf doodad position+rotation on load
Already had a guard for scale; extending to position/rotation too.
A WoB with non-finite doodad transforms produces NaN model matrices
that propagate into the M2 instance SSBO and crash the GPU.
2026-05-06 07:06:25 -07:00
Kelsi
3614a7dcd5 fix(zones): clamp discovery mapId and tile coords on scan
Mirrors the editor-side ZoneManifest sanitize on the discovery
scanner used by the launcher and asset manager. A custom_zones/
zone with bad mapId or out-of-range tile coords would otherwise
appear in the picker and silently fail when the user selects it.
2026-05-06 07:00:04 -07:00
Kelsi
1e378fb4ce fix(wot): clamp tile coords and scrub NaN doodad/WMO placements
A WOT JSON could carry tile coords outside 0..63 (would compute
chunk world positions tens of thousands of units off-grid) or NaN
position/rotation values on doodad/WMO placements (would propagate
into rendering matrices and produce invisible geometry).
2026-05-06 06:51:51 -07:00
Kelsi
185b7b522d fix(wob): sanitize boundRadius + per-group boundMin/Max at save time
Same float-NaN scrub for WoB save matching the WHM/WOC/WOM saves.
Building boundRadius defaults to 1.0 if non-finite; per-group bounds
zero out non-finite components (would otherwise corrupt the cull
frustum).
2026-05-06 06:39:49 -07:00
Kelsi
d25654d11a fix(wom): sanitize boundRadius/min/max floats at save time
Mirrors the WHM and WOC save sanitize. boundRadius defaults to 1.0 if
non-finite (matches load-time default); boundMin/boundMax components
zero out non-finite values. Prevents an in-memory model with a NaN
spike (e.g. mid-edit) from being persisted into the WOM and requiring
load-time cleanup forever after.
2026-05-06 06:36:46 -07:00
Kelsi
663d34af0d fix(woc): sanitize triangle vertices + bounds at save time
In-memory collision can be polluted by addMesh on bad input (e.g. a
WMO with NaN vertex positions). Without this, the save would persist
that NaN into the WOC and the load-time guards would have to clean
it up forever. Now scrubs vertices and bounds at write time, matching
the WHM save sanitize.
2026-05-06 06:35:05 -07:00
Kelsi
5019e21787 fix(wom): writeStr helper truncates length-prefixed strings to fit u16 length
Same fix as WoB save just got. Without truncation a model name or
texture path over 65535 chars would silently get a wrap-around length
and corrupt the file.
2026-05-06 06:25:33 -07:00
Kelsi
361ff712d7 fix(wob): writeStr helper truncates length-prefixed strings to fit u16 length
Without truncation, names over 65535 chars would silently get a wrap-
around length value and produce a corrupt file (the actual string would
be longer than the saved length, shifting everything after it). Single
shared writeStr lambda replaces five copy-pasted (uint16 length + bytes)
write blocks.
2026-05-06 06:23:35 -07:00
Kelsi
be64298218 fix(dbc): cap JSON DBC string sizes (4KB/string, 64MB total) + NaN floats
JSON DBC values are mostly small integers, but a malicious file could
stuff 100MB strings into every cell to OOM the stringBlock (which has
no per-string or total cap). Added 4KB per-string + 64MB total caps —
fields exceeding either are zeroed. Float fields also get NaN scrub
(same pattern as the earlier vertex/keyframe guards).
2026-05-06 06:19:01 -07:00
Kelsi
719951976d fix(wom+wob): reject path traversal in WOM texture paths + WOB material/group texPaths
Same defensive check as the WoB doodad path guard. Texture paths from
hostile WOM/WoB are passed to the asset manager; '..' or absolute paths
could probe outside the assets/ tree. Now cleared on detection — slot
survives but loads no texture (renderer falls back to white).

Single shared rejectTraversal lambda in WoB to avoid copy-paste.
2026-05-06 06:16:54 -07:00
Kelsi
c4463ba96e fix(wob): reject doodad paths with traversal/absolute components
Doodad model paths from a WoB are passed to the asset manager via
outModel.doodadNames. The asset manager only reads files, but '..' or
absolute paths from a hostile WoB could probe for files outside the
expected assets/ tree. Now clears the modelPath on traversal — the
doodad slot survives but loads no model.
2026-05-06 06:14:22 -07:00
Kelsi
b5a9ce7816 fix(assets): cap PNG override texture dimensions at 8K to prevent OOM
stbi_load happily decodes any PNG up to 32K x 32K — at 4 bytes/pixel
that's 4GB which OOMs the editor before the override even returns.
WoW textures top out at 4K; 8K cap leaves headroom for HD upgrades
without enabling abuse. Also widens the wxh multiplication to size_t
to defeat int overflow on 8K x 8K images.
2026-05-06 06:09:13 -07:00
Kelsi
2d8c843704 fix(dbc): cap JSON DBC fieldCount/recordCount to prevent OOM on hostile file
Real DBCs cap at ~250 fields and a few million records (Spell.dbc is
the biggest at ~50K rows). A malicious JSON DBC declaring fieldCount=
1G or recordCount * recordSize > 256MB would OOM the recordData
allocation. Now rejects upfront — JSON DBCs are user-shareable so a
zone export downloaded from a forum should not be able to OOM the
client by including a bad data table.
2026-05-06 06:07:09 -07:00
Kelsi
5b6f59bbbd fix(adt): scrub NaN/inf in MDDF + MODF placement floats
ADT placement positions and rotations are loaded as raw floats from the
binary chunks. A corrupted MDDF/MODF entry could feed NaN into the
M2/WMO instance transform and crash render. Now position/rotation are
scrubbed for both MDDF doodads and MODF buildings; MODF also scrubs the
extentLower/extentUpper bounding box used for cull tests.
2026-05-06 06:05:17 -07:00
Kelsi
c0c1be1c9e fix(wob): cap material/doodad path lengths + portal vertex count
Three more per-record sanity bounds that the per-group sweep didn't
cover:
  - material.texturePath length cap (1KB) — was unbounded
  - doodad.modelPath length cap (1KB) — was unbounded
  - portal.vertexCount cap (4096) — real portals are 4-12 verts;
    >4K is corrupt and would OOM the resize
2026-05-06 05:52:58 -07:00
Kelsi
93edf1bd55 fix(wob): per-group count sanity bounds + group name length cap
The WoB top-level header sanity bounds catch obviously-bad totals, but
each group's vc/ic/tc was still unbounded. A corrupted group could
declare 4G vertices and OOM the resize before the next group even
started. Now per-group: vc<=1M, ic<=4M, tc<=1K, name<=1KB.
2026-05-06 05:49:15 -07:00
Kelsi
cb7f11f2ea fix(wom): cap total keyframes at 10M to prevent OOM on hostile model
Per-bone-anim cap of 10K keyframes still let a malicious file allocate
up to 1024 anims × 512 bones × 10K keys = 5.24B keyframes — multi-GB
pre-OOM allocation. Now tracks total across the whole model and stops
allocating after 10M (real models stay well under 100K). When the cap
is hit we still seek past the remaining payload to keep file alignment
intact for whatever follows.
2026-05-06 05:46:55 -07:00
Kelsi
a7d62d1af9 fix(woc): reject corrupted triCount + clamp out-of-range tile coords
Header sanity bounds for WOC matching the WOM/WoB ones. A whole-tile
collision mesh maxes at ~32K terrain tris + a few thousand building
overlay tris; triCount > 2M is corrupted and would OOM. Tile coords
are 0..63 in WoW; clamp to 32 with warning when bogus.
2026-05-06 05:44:37 -07:00
Kelsi
90289ba48b fix(wob+wom): reject corrupted header counts before allocating
Adds upfront sanity bounds to both WoB and WOM load:
  WOM: vert<=1M, index<=4M, tex<=1K
  WOB: groups<=4K, portals<=8K, doodads<=64K
Real WoW models stay well under these limits (M2 vert is uint16 anyway).
Without these checks a corrupted header could trigger a multi-GB
allocation and OOM the process before we finish reading the body. Also
caps name length to 1KB on WoB load (already done on WOM).
2026-05-06 05:42:50 -07:00
Kelsi
53780de6da fix(wob): clamp out-of-range group indices + reject absurd texture path lengths
Mirrors the WOM index-clamp + texture-path-length guards. Out-of-range
indices into the WMO group's vertex buffer would crash the GPU draw.
Texture path length over 1KB indicates a corrupted/truncated WoB; clamp
to 0 to prevent allocating 65KB-string buffers per bad entry.
2026-05-06 05:36:20 -07:00
Kelsi
a2eaf3965a fix(wom): clamp out-of-range indices + reject absurd texture path lengths
Out-of-range indices were a silent vector overrun on the GPU side that
could crash the vertex shader on some drivers. Replace with 0 rather
than dropping so triangle counts stay aligned (a degenerate triangle is
harmless, an off-by-one indexing the wrong vertex is silent corruption).

Texture path length over 1KB is almost certainly a corrupted or
truncated file — was previously read into a 65KB-string allocation per
entry which could exhaust memory on a malicious file.
2026-05-06 05:34:41 -07:00