Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Maya Live link: no allocation ahead of the bytes (security read): a Hello is capped at 256 bytes before pairing, payloads grow a MiB at a time as they arrive; tests for a 1 GiB claim before and after pairing; notes say real Maya and Windows are not verified yet
islandmed97426be5ddd8
diff --git a/changes/feat-maya-live.md b/changes/feat-maya-live.mdindex b10a698c..cd408d76 100644--- a/changes/feat-maya-live.md+++ b/changes/feat-maya-live.md@@ -18,6 +18,8 @@ added: **Maya Live link** (#42): opt-in, off at every start and never rememberedsecurity: New local listener, the Maya Live link: per-user socket / pipe only, opt-in with a warning each time,pairing code, mesh data only (SECURITY.md).testers:+ - NOT YET VERIFIED in a real Maya (tests use a mocked maya.cmds) or on Windows (the named-pipe client): these+ are the first runs; report anything odd on #42.- Any OS with Maya 2022+: install the shelf again (six buttons). File > Maya > Live on in SculptForge, Live on theshelf; sculpt a stroke: Maya updates within about half a second; edit the mesh in Maya: SculptForge updates.No ping-pong (each change arrives once; no extra undo steps).@@ -25,4 +27,6 @@ testers:Link on the shelf, paste: Maya follows a stroke while you draw it. Click Live link on in the top bar: off.- Windows: the same through the named pipe; a wrong code is refused.----Security read by input before merge (Tony approved the link 11-06 ~19:10 in the mayalive session).+Security read by input: OK after the pre-pairing allocation fix (readFrame caps a Hello at 256 bytes and grows+payloads a MiB at a time as bytes arrive). Tony approved the link 11-06 in the mayalive session. Not verified in real+Maya or on Windows yet.diff --git a/src/link/MayaLink.cpp b/src/link/MayaLink.cppindex a58abc39..c29d8ba4 100644--- a/src/link/MayaLink.cpp+++ b/src/link/MayaLink.cpp@@ -445,7 +445,7 @@ std::vector<MayaLinkMesh> MayaLinkServer::takeReceived() {}bool MayaLinkServer::readFrame(AiLinkConn& conn, MayaLinkType& type, std::string& payload, int firstByteMs,- std::string& error) {+ uint64_t maxLength, std::string& error) {char header[kMayaLinkHeaderBytes];size_t got = 0;int wait = firstByteMs;@@ -464,19 +464,29 @@ bool MayaLinkServer::readFrame(AiLinkConn& conn, MayaLinkType& type, std::stringreturn false;}got += size_t(n);- wait = kMayaLinkFrameMs;+ wait = frameMs_;if (stopping_) return false;}uint64_t length = 0;if (!parseMayaLinkHeader(header, type, length, error)) return false;- payload.assign(size_t(length), '\0');- for (size_t at = 0; at < payload.size();) {- const long long n = conn.readBytes(payload.data() + at, payload.size() - at, kMayaLinkFrameMs);+ if (length > maxLength) { // (before pairing: only a Hello's size)+ error = "a message over the size cap";+ return false;+ }+ // The payload grows as its bytes arrive, a MiB at a time: a header's claim alone never allocates.+ payload.clear();+ while (payload.size() < length) {+ const size_t at = payload.size();+ payload.resize(at + size_t(std::min<uint64_t>(length - at, kMayaLinkReadChunk)));+ largestBuffer_ = std::max<size_t>(largestBuffer_, payload.size());+ const long long n = conn.readBytes(payload.data() + at, payload.size() - at, frameMs_);if (n <= 0) {+ payload.clear();+ payload.shrink_to_fit();error = n < 0 ? "closed" : "timed out";return false;}- at += size_t(n);+ payload.resize(at + size_t(n));if (stopping_) return false;}return true;@@ -500,7 +510,7 @@ bool MayaLinkServer::serve(AiLinkConn& conn) {std::string error, payload;MayaLinkType type{};// Pairing first: a Hello with the code within kMayaLinkHelloMs, or the connection closes.- if (!readFrame(conn, type, payload, kMayaLinkHelloMs, error) || type != MayaLinkType::Hello) {+ if (!readFrame(conn, type, payload, kMayaLinkHelloMs, kMayaLinkMaxHello, error) || type != MayaLinkType::Hello) {if (error == "closed") return false; // (a probe: another window checking whether the link is on)++refused_;event("refused: " + std::string(error.empty() ? "no pairing code" : error));@@ -531,7 +541,7 @@ bool MayaLinkServer::serve(AiLinkConn& conn) {error = "closed";break;}- if (!readFrame(conn, type, payload, 10, error)) {+ if (!readFrame(conn, type, payload, 10, kMayaLinkMaxPayload, error)) {if (error.empty()) continue; // nothing this timebreak;}diff --git a/src/link/MayaLink.h b/src/link/MayaLink.hindex 88f16e09..5fa93e69 100644--- a/src/link/MayaLink.h+++ b/src/link/MayaLink.h@@ -43,6 +43,8 @@ inline constexpr uint32_t kMayaLinkMaxVertices = 64u << 20;inline constexpr size_t kMayaLinkCodeChars = 32;inline constexpr int kMayaLinkHelloMs = 5000; // to send Hello after connectinginline constexpr int kMayaLinkFrameMs = 30000; // no byte of a started frame for this long: closed+inline constexpr uint64_t kMayaLinkMaxHello = 256; // before pairing, no frame may claim more+inline constexpr size_t kMayaLinkReadChunk = 1u << 20; // payloads grow as bytes arrive, a MiB at a timeinline constexpr unsigned long long kMayaLinkStreamNs = 100'000'000ull; // mid-stroke Points, at most this oftenenum class MayaLinkType : uint16_t { Hello = 1, Welcome = 2, Mesh = 3, Points = 4, Bye = 5 };@@ -111,6 +113,10 @@ public:std::string clientName() const;// Counts for the UI and tests: refused connections (wrong code, a second client, bad frames).int refused() const { return refused_; }+ // Tests: the biggest payload buffer a read ever held (claims never allocate ahead of the bytes), and a shorter+ // stall limit than kMayaLinkFrameMs.+ size_t largestBuffer() const { return largestBuffer_; }+ void setFrameTimeoutMs(int ms) { frameMs_ = ms; }void send(MayaLinkMesh mesh);void send(MayaLinkPoints points);std::vector<MayaLinkMesh> takeReceived();@@ -119,7 +125,8 @@ public:private:void run();bool serve(AiLinkConn& conn);- bool readFrame(AiLinkConn& conn, MayaLinkType& type, std::string& payload, int firstByteMs, std::string& error);+ bool readFrame(AiLinkConn& conn, MayaLinkType& type, std::string& payload, int firstByteMs, uint64_t maxLength,+ std::string& error);bool flush(AiLinkConn& conn);void event(std::string text);@@ -127,6 +134,8 @@ private:std::thread thread_;std::atomic<bool> running_{false}, stopping_{false}, connected_{false};std::atomic<int> refused_{0};+ std::atomic<size_t> largestBuffer_{0};+ std::atomic<int> frameMs_{kMayaLinkFrameMs};std::string code_, endpoint_;mutable std::mutex mutex_;std::string client_;diff --git a/tests/test_maya_live.cpp b/tests/test_maya_live.cppindex 1e2eaac0..1487cc34 100644--- a/tests/test_maya_live.cpp+++ b/tests/test_maya_live.cpp@@ -340,6 +340,16 @@ TEST(maya_link_server_pairs_and_streams) {CHECK(c.writeAll(http.data(), http.size()));CHECK(waitFor([&] { return server.refused() == 2; }) && !server.connected());}+ // Before pairing, a header claiming 1 GiB is refused on the claim: nothing near that size is allocated.+ {+ AiLinkConn c;+ CHECK(aiLinkConnect(c, endpoint, err));+ std::string big = mayaLinkFrame(MayaLinkType::Hello, {});+ for (int i = 0; i < 8; ++i) big[8 + size_t(i)] = char(((1ull << 30) >> (8 * i)) & 0xff);+ CHECK(c.writeAll(big.data(), big.size()));+ CHECK(waitFor([&] { return server.refused() == 3; }) && !server.connected());+ CHECK(server.largestBuffer() <= kMayaLinkMaxHello);+ }// The right code: Welcome, then meshes both ways.AiLinkConn c;CHECK(aiLinkConnect(c, endpoint, err));@@ -379,6 +389,26 @@ TEST(maya_link_server_pairs_and_streams) {const std::string bye = mayaLinkFrame(MayaLinkType::Bye, {});CHECK(c.writeAll(bye.data(), bye.size()));CHECK(waitFor([&] { return !server.connected(); }));++ // After pairing, a frame claiming 1 GiB that sends 10 bytes and stalls: it times out, and the buffer never grew+ // past one read chunk (the claim isn't allocated up front).+ server.setFrameTimeoutMs(300);+ {+ AiLinkConn s;+ CHECK(aiLinkConnect(s, endpoint, err));+ const std::string h = encodeMayaLinkHello(server.code(), "staller");+ CHECK(s.writeAll(h.data(), h.size()));+ CHECK(readFrame(s, t, p) && t == MayaLinkType::Welcome);+ CHECK(waitFor([&] { return server.connected(); }));+ std::string big = mayaLinkFrame(MayaLinkType::Mesh, std::string(10, 'x'));+ for (int i = 0; i < 8; ++i) big[8 + size_t(i)] = char(((1ull << 30) >> (8 * i)) & 0xff);+ CHECK(s.writeAll(big.data(), big.size()));+ CHECK(waitFor([&] { return !server.connected(); }, 5000));+ CHECK(server.largestBuffer() <= 10 + kMayaLinkReadChunk); // (at most one chunk ahead of what arrived)+ std::string last, ev;+ while (!(ev = server.takeEvent()).empty()) last = ev;+ CHECK(last == "disconnected: timed out");+ }server.stop();CHECK(aiLinkFileMode(endpoint) < 0); // the socket file is gone when the link is offunsetenv("SF_AI_LIVE_DIR");