Session::compute_json, compute_bincode and dimension silently answer for a different expression when the Term belongs to another session

Open Beginner friendly
#349 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
73/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, rust

Research direction

Read the C++ client methods in client.hpp: compute_json, compute_bincode, dimension, eval, and compute (around the line references in the issue). Compare how they handle a Term from another Session, then run the relevant C++ client tests or reproduce the supplied example. Done means all four methods reject a foreign-session Term consistently with compute.

Written by the indexing model from the issue text.

Description

area/api-bindings good first issue help wanted kind/contract severity/3-major

Session::compute_json, compute_bincode and dimension never check which session a Term belongs to, so a term from another session is silently read as this session's node with the same handle — the call returns the compute record of a different expression, while Session::compute rejects the very same term.

// repro.cpp
#include <cstdio>
#include "rssn/client.hpp"
using namespace rssn::client;
int main() {
  Session a, b;
  const auto x = a.sym("x");   // handle 9 in a
  const auto y = b.sym("y");   // handle 9 in b
  std::printf("x.handle=%u y.handle=%u\n", x.handle(), y.handle());
  try { a.compute(y); } catch (const Error &e) {
    std::printf("a.compute(y)      -> %s: %s\n", status_name(e.status()), e.what()); }
  std::printf("a.compute_json(y) -> %s\n", a.compute_json(y).c_str());
  std::printf("b.compute_json(y) -> %s\n", b.compute_json(y).c_str());
  std::printf("a.dimension(y)    -> [%s]\n", a.dimension(y).c_str());
  std::printf("a.compute_bincode(y)==a.compute_bincode(x): %d\n",
              a.compute_bincode(y) == a.compute_bincode(x));
}

Actual output (twice, identical):

x.handle=9 y.handle=9
a.compute(y)      -> invalid_argument: the request belongs to another session
a.compute_json(y) -> {"diagnostic_codes":[],"diagnostics":[],"dimension":"?x","error":null,"iterations":1,"reduced":true,"term":"x","value":null}
b.compute_json(y) -> {"diagnostic_codes":[],"diagnostics":[],"dimension":"?y","error":null,"iterations":1,"reduced":true,"term":"y","value":null}
a.dimension(y)    -> [?x]
a.compute_bincode(y)==a.compute_bincode(x): 1

Why it is wrong: the record returned for y describes x — "term":"x" instead of "term":"y", and the bincode is byte-identical to the bincode of x. Session::compute (client.hpp:868-874) treats the same argument as an error ("the request belongs to another session"), so the four members disagree about a term that does not belong to the session. Handles are per-session node indices, so this is a silent wrong answer, not a diagnostic: a caller that logs compute_json of a request built elsewhere records a different expression.

Mechanism: compute_json (client.hpp:545), compute_bincode (client.hpp:556) and dimension (client.hpp:568) pass term.handle() to the C entry point without the term.session() != pointer_ guard that compute performs. Session::eval (client.hpp:578) has the same hole in the other direction: it delegates to term.eval(), so it evaluates in the term's session. The guard belongs in all four.

rssn 0.3.0, C++ client (header-only) over the release C library, Windows x86_64.

Dominant language
Rust
Stars
36
Forks
3
Avg merge
14h 51m
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Apich-Organization/rssn

All issues in Apich-Organization/rssn

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.