Skip to content

[ENG-2416] Add write_sta_db and read_sta_db commands - #69

Open
gigeresk wants to merge 12 commits into
mainfrom
stadb
Open

[ENG-2416] Add write_sta_db and read_sta_db commands#69
gigeresk wants to merge 12 commits into
mainfrom
stadb

Conversation

@gigeresk

@gigeresk gigeresk commented Aug 13, 2026

Copy link
Copy Markdown

This PR adds StaDBs, which are serialized STA sessions. They can be written with write_sta_db and read with read_sta_db. Reading an StaDB session will clear state before restoring the serialized session.
Rewrites after restore are byte-idempotent; as such, some data structures need to be sorted before serialization.
StaDBs are considered valid across builds of OpenSTA with the same stadb_version and stadbAbiGuard(), which is a hash of sizeof for Vertex, Edge, Liberty, etc. Not shareable across libc++/libstdc++ builds due to various sizeof differences.

Covered in serialization

Liberties (NLDM), SDC, Netlists, Graph and search (e.g. report_checks)

Not covered in serialization (out of scope)

Parasitics (SPEF) are omitted, MCMM (i.e. anything >1 Scene throws), CCS is dropped, statistical throws

Open questions:

  • Making StaDb a friend to access private members is less code on the core but may raise concerns upstream, leave this as future work?

@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds serialization and restoration of supported OpenSTA sessions through write_sta_db and read_sta_db.

  • Adds the StaDB binary container, codecs, and serializers for Liberty, network, graph, SDC, and search state.
  • Integrates the new Tcl and C++ APIs into the build and documentation.
  • Adds regression coverage for snapshot fidelity and deterministic rewrites.

Confidence Score: 0/5

The PR is not safe to merge because crafted StaDB files can still terminate OpenSTA through oversized allocations, and a failed restore still destroys the active session.

The new 64 GiB section and 512 GiB file caps still allow infeasible attacker-controlled vector allocations, while readStaDb clears the existing session before fallible section decoding and provides no rollback when decoding fails.

Files Needing Attention: stadb/StaDbFormat.hh, stadb/StaDbFile.cc, and stadb/StaDbReader.cc

Security Review

The new allocation limits do not close the previously reported denial-of-service paths: crafted input can still request a decompressed allocation up to 64 GiB or a whole-file allocation up to 512 GiB before being rejected.

How this was verified: Both accepted sizes flow directly into vector allocations, and the configured limits remain far above realistically available process memory.

Important Files Changed

Filename Overview
stadb/StaDbFormat.hh Introduces allocation caps, but 64 GiB per section and 512 GiB per file remain large enough for the previously reported memory-exhaustion paths.
stadb/StaDbFile.cc Adds pre-allocation checks, but accepted attacker-controlled sizes still flow directly into potentially infeasible vector allocations.
stadb/StaDbReader.cc Adds cleanup for failed in-place restores, but still destroys the previous session and leaves the caller with an empty one.
stadb/StaDbGraph.cc Restores graph, levelization, delay, and period-check state; malformed collection counts also reinforce the need for effective aggregate resource limits.
stadb/StaDbWriter.cc Coordinates deterministic serialization of supported session sections and rejects unsupported session configurations.

Sequence Diagram

sequenceDiagram
  participant Tcl as read_sta_db
  participant File as DbFileReader
  participant STA as Active Sta
  participant Restore as Section decoders
  Tcl->>File: read and validate container
  File-->>Tcl: validated sections
  Tcl->>STA: clearSession()
  Tcl->>Restore: restore Liberty/network/graph/SDC/search
  alt restore succeeds
    Restore-->>Tcl: restored session
  else section decoding throws
    Restore-->>Tcl: exception
    Tcl->>STA: clearSession()
    Tcl-->>Tcl: rethrow with empty session
  end
Loading

Reviews (3): Last reviewed commit: "File safety + sta docs" | Re-trigger Greptile

Comment thread stadb/DbFile.cc
Comment thread stadb/StaDbReader.cc Outdated
@gigeresk

Copy link
Copy Markdown
Author

@greptile

Comment thread stadb/DbFile.cc
@gigeresk

Copy link
Copy Markdown
Author

@greptile

Comment thread stadb/DbFormat.hh
Comment thread stadb/DbFormat.hh
Comment thread stadb/StaDbReader.cc Outdated
@gigeresk
gigeresk requested a review from stanminlee August 13, 2026 21:23
@gigeresk gigeresk changed the title Add write_sta_db and read_sta_db commands [ENG-2416] Add write_sta_db and read_sta_db commands Aug 13, 2026
@linear-code

linear-code Bot commented Aug 13, 2026

Copy link
Copy Markdown

ENG-2416

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants