Skip to content

Entity map: relative @id refs expand per page without a cap (refs and entity_edges rows can exceed SQLite limits) #2135

Closed

Description

@nc9

Found while reviewing release batch 2 (#2132, pub#1956 entity map storage).

A relative JSON-LD @id reference (e.g. {"@id":"#n"}) expands to the full page URL before it is stored. One page with 300 KB of JSON-LD (20k relative refs) on an 1,800-character URL produced a single 36.6 MB entity_map_pages.refs row, 122 times the input. At the 10 MiB body cap that is about 1.2 GB, past SQLite's maximum value length. saveEntityMap then throws, storeEntityMap swallows the error, and the crawl reads as having no entity map at all. entity_edges already stores the same expanded targets, so the exposure predates pub#1956; refs roughly doubles it. A hostile page can do this, so it is an audit-a-hostile-site robustness issue.

Also: sqlite.ts ~4610 JSON.parse(row.refs) is unguarded, so one corrupt row fails loadEntityMap for the whole crawl.

Acceptance Criteria

  • Per-page stored refs and entity edges are capped (e.g. 1,000 sorted keys plus a total count), with the cap noted in the stored data; a test with 20k relative refs on a long URL stores a bounded row
  • A page that exceeds the cap still gets an entity map for the crawl (the write does not fail as a whole)
  • A corrupt refs row is skipped with a warning; it does not fail loadEntityMap for the crawl

nik

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsize: S

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions