Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
HEAD (Docker image matrixorigin/matrixone:latest)
Commit ID
d239386
Other Environment Information
- MatrixOne version: v4.2.1
- Docker image ID: sha256:c95d1b468e3fc5f4f2b377da14f4601e7efefa6eb143758636d60114a5bbb436
- Image creation time: 2026-09-03T14:57:40Z
- Client: mysql CLI over the MySQL protocolActual Behavior
SHA2(payload, 256) hashes only the first 65,535 bytes when payload is a
160,000-byte LONGTEXT value. The returned digest is exactly the digest of
LEFT(payload, 65535), not the digest of the complete value.
Observed result:
payload_bytes: 160000
SHA2(payload, 256): 09ab7495d3e61a76f0deb12cb0306f0696cbb17ffc12131368c7a939f12f56d3
SHA2(LEFT(payload,65535), 256): 09ab7495d3e61a76f0deb12cb0306f0696cbb17ffc12131368c7a939f12f56d3
SHA-256 over all 160000 bytes: e5dcc6668e15a3a785d911afb58f0d038c1412806a2c54d4c6253a6a7060f356
CAST(payload AS TEXT) preserves all 160,000 bytes, but
SHA2(CAST(payload AS TEXT), 256) still returns the 65,535-byte-prefix digest.
Expected Behavior
SHA2(expr, 256) should hash the complete byte sequence represented by
expr. For this input it should return:
e5dcc6668e15a3a785d911afb58f0d038c1412806a2c54d4c6253a6a7060f356
Steps to Reproduce
DROP TABLE IF EXISTS sha2_longtext_repro;
CREATE TABLE sha2_longtext_repro (payload LONGTEXT NOT NULL);
INSERT INTO sha2_longtext_repro
VALUES (CONCAT(
REPEAT('x', 40000),
REPEAT('x', 40000),
REPEAT('x', 40000),
REPEAT('x', 40000)
));
SELECT
OCTET_LENGTH(payload) AS payload_bytes,
LOWER(SHA2(payload, 256)) AS actual_full_digest,
LOWER(SHA2(LEFT(payload, 65535), 256)) AS prefix_digest,
OCTET_LENGTH(CAST(payload AS TEXT)) AS cast_text_bytes,
LOWER(SHA2(CAST(payload AS TEXT), 256)) AS cast_text_digest
FROM sha2_longtext_repro;Independent expected digest:
python3 -c 'import hashlib; print(hashlib.sha256(b"x" * 160000).hexdigest())'Additional information
This can silently invalidate integrity checks for persisted JSON, manifests,
WAL payloads, or other values larger than 65,535 bytes. OCTET_LENGTH and a
raw client read both report the full value, so the stored LONGTEXT itself is
not truncated; the truncation occurs in the SHA2 evaluation path.
For comparison, CAST(payload AS CHAR) has length 65,535 while
CAST(payload AS TEXT) has length 160,000 on the same row. The SHA2 result
behaves as if the input had passed through the bounded CHAR representation.
Activity
fix(function): preserve wide strings in SHA2 (#28104)
slyunnn commentedon Sep 4, 2026
Regression and extended verification for #28103 (2026-09-04)
Verification Environment
origin/mainat8a83e3e31e4297ea14e58afd8c14837513a6cf54—perf(analyze): publish table-wide cardinality stats (#28067).a6f3988587bdba967a75015a0a12f9bf3a2c9bac—fix(function): preserve wide strings in SHA2; it is included in the verifiedorigin/main.LOG + TN + one CN; the CN MySQL endpoint was127.0.0.1:26001. SQL used the MySQL/TCP protocol through MOTR.127.0.0.1:16001,127.0.0.1:16002, and Proxy127.0.0.1:6001were not covered. An existing non-baseline Docker service on6001was intentionally not used.TestSHA2PreservesWideStringInputs,TestSHA2StillFormatsScalarInput, andTestSHA2PreservesEveryMySQLStringDomain.What Was Covered
160000-byteLONGTEXTreturns the fullSHA2(payload, 256)digeste5dcc6668e15a3a785d911afb58f0d038c1412806a2c54d4c6253a6a7060f356, rather than theLEFT(payload, 65535)digest;full_not_prefixis1.CAST(payload AS TEXT)retains160000bytes and produces the same full SHA-256 digest;CAST(payload AS CHAR)remains the expected65535-byte control behavior.65536-byteMEDIUMTEXTinput returns a full SHA-512 digest distinct fromLEFT(payload, 65535), covering the first byte beyond the truncation boundary.BLOBbytes0x000102FFare hashed without string truncation or binary-byte loss.SHA2(NULL, 256)returnsNULL.CHAR,VARCHAR,BINARY,VARBINARY,BLOB, andTEXTdomains, scalar formatting, wide strings, and binary bytes passed focused CGo tests.127.0.0.1:16001and127.0.0.1:16002, or Proxy routing through127.0.0.1:6001; the defect is a local function-input width conversion issue and does not require those paths for reproduction.Findings
The fix retains the original string domain when evaluating
SHA2, so inputs larger than65535bytes are no longer coerced to a boundedVARCHARrepresentation. The originalLONGTEXTreproduction and the immediateMEDIUMTEXTboundary both return full-input digests, while scalar, text, binary, andNULLcontrols remain correct.Large-data regression is not needed. This defect depends on the
65535-byte string-width boundary rather than row count, block/batch boundaries, memory or spill, concurrency, data skew, network transfer, or resource scale. The stable65536-byte boundary payload and the original160000-byte payload directly cover the relevant execution boundary.MOTR / BVT Coverage
suites/14_issue_regression/t/issue_28103_sha2_longtext.testandsuites/14_issue_regression/r/issue_28103_sha2_longtext.result.14_issue_regression.issue_28103_sha2_longtextsuccessfully against the locally built latest-main CN:13/13statements passed in both runs.test/issue-28103-sha2-longtext; commit159c230(test: add MOTR regression for #28103), pushed by SSH.4f4043d. No issue-specific PR was created.Final Conclusion
Fixed. Latest
origin/maincontains the related fix and passes the original reproduction plus targeted happy-path, unhappy-path, boundary, binary compatibility, and focused unit coverage. Large-data regression is not required for the reasons above.fix(function): preserve wide strings in SHA2 (matrixorigin#28104)
fix(function): preserve wide strings in SHA2 (matrixorigin#28104)
fix(function): preserve wide strings in SHA2 (matrixorigin#28104)