Skip to content

refactor: validate label / edge-triplet IDs at PropertyGraph API boundary#422

Merged
zhanglei1949 merged 3 commits into
alibaba:mainfrom
zhanglei1949:zl/property-graph-label-validation
Jun 1, 2026
Merged

refactor: validate label / edge-triplet IDs at PropertyGraph API boundary#422
zhanglei1949 merged 3 commits into
alibaba:mainfrom
zhanglei1949:zl/property-graph-label-validation

Conversation

@zhanglei1949
Copy link
Copy Markdown
Member

What do these changes do?

Harden PropertyGraph's label-id and edge-triplet validation so that bad caller-supplied IDs no longer become undefined behavior in Release builds, and unify the existing private check helpers so the string and label_t overloads behave consistently.

  • Add label_t overloads of the private helpers and make all four overloads const. Both edge_triplet_check overloads now delegate per-vertex validation to vertex_label_check, so they share logic and produce equally granular errors:
    Status vertex_label_check(const std::string&) const;
    Status vertex_label_check(label_t) const;
    Status edge_triplet_check(const std::string&, const std::string&,
                              const std::string&) const;
    Status edge_triplet_check(label_t, label_t, label_t) const;
  • Mutating APIs (BatchAddVertices, BatchDeleteVertices, DeleteVertex ×2, DeleteEdge, BatchDeleteEdges ×2, AddVertex, UpdateVertexProperty, UpdateEdgeProperty) now RETURN_IF_NOT_OK(vertex_label_check(...) / edge_triplet_check(...)) instead of assert(...) or relying on the callee to catch the bad ID.
  • Non-Status accessors (get_vertex_table ×2, GetVertexPropertyColumn ×2, GetVertexSet, LidNum, VertexNum, IsValidLid, get_lid, GetOid) now call schema_.ensure_vertex_label_valid(...) (throws InvalidArgumentException) — the only viable signal channel for non-Status returns.
  • GetVertexPropertyColumn(label, col_id) additionally bounds-checks col_id against the label's property count.
  • Unify error wording across overloads: "Vertex label '<name>' is not valid" / "Vertex label id <N> is not valid"; same "Edge triplet <...> is not valid" shape. Drop the LOG(ERROR) calls from the existing string-based helpers (caller decides).

No behavior change for valid inputs. Verified no tests assert on the old error wording.

Background

These changes were originally bundled inside the zl/update-txn-cow branch (PR #370 split work) but have no semantic dependency on the workspace/checkpoint or COW refactor. Splitting them out keeps those downstream PRs focused and lets this hardening land independently against main.

Related issue number

Fixes #421

…dary

Previously several PropertyGraph public APIs trusted caller-supplied
label_t / edge-triplet IDs without validation: mutating ops relied on
assert() (compiled out in Release) and non-Status accessors did no check
at all, so an invalid label_t became out-of-bounds vector access on
vertex_tables_[label] -- undefined behavior in Release.

- Add label_t overloads of vertex_label_check / edge_triplet_check, and
  make all four overloads const + share logic (edge_triplet_check now
  delegates per-vertex validation to vertex_label_check).
- Mutating APIs: replace asserts / missing checks with
  RETURN_IF_NOT_OK(vertex_label_check / edge_triplet_check) so invalid
  IDs surface as ERR_INVALID_ARGUMENT instead of UB.
- Non-Status accessors (get_vertex_table, GetVertexPropertyColumn,
  GetVertexSet, LidNum, VertexNum, IsValidLid, get_lid, GetOid) now call
  schema_.ensure_vertex_label_valid(...) -- throws InvalidArgumentException,
  the only viable signal channel for non-Status returns.
- GetVertexPropertyColumn(label, col_id): also bounds-check col_id
  against the label's property count.
- Unify error wording across string / label_t overloads ("Vertex label
  '<name>' is not valid" / "Vertex label id <N> is not valid"; same
  "Edge triplet <...> is not valid" shape) so behavior is consistent
  regardless of which overload the caller hits.

No behavior change for valid inputs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens PropertyGraph’s public API boundary by validating caller-supplied vertex label IDs and edge-triplet IDs before they can trigger undefined behavior (especially in Release builds where assert is compiled out), and it consolidates the internal validation helpers so string- and label_t-based call sites behave more consistently.

Changes:

  • Introduces label_t overloads for vertex_label_check / edge_triplet_check and makes the helpers const, with edge-triplet checks delegating per-vertex validation to vertex_label_check.
  • Replaces a number of assert(...)-based checks in mutating APIs with RETURN_IF_NOT_OK(...) so invalid inputs return ERR_INVALID_ARGUMENT rather than risking UB.
  • Adds label validation for non-Status accessors via schema_.ensure_vertex_label_valid(...), and adds a new bounds check in GetVertexPropertyColumn(label, col_id).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/storages/graph/property_graph.cc Replaces assert-based validation with Status-returning checks; adds unified helper implementations for label/triplet validation.
include/neug/storages/graph/property_graph.h Adds label validation to inline accessors and introduces a new column-id bounds check for GetVertexPropertyColumn(label, col_id).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/neug/storages/graph/property_graph.h
Comment thread src/storages/graph/property_graph.cc
void loadSchema(const std::string& filename);
inline std::shared_ptr<RefColumnBase> GetVertexPropertyColumn(
uint8_t label, int32_t col_id) const {
schema_.ensure_vertex_label_valid(label);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning null or throw exception?

@zhanglei1949 zhanglei1949 merged commit 020cae2 into alibaba:main Jun 1, 2026
20 of 21 checks passed
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.

PropertyGraph: harden label / edge-triplet validation at API boundary

3 participants