{"record":{"id":"9d58d1fd2e770b76","repo":"phalcon/cphalcon","slug":"invalid-wkb-truncated-buffer","errorCode":null,"errorMessage":"Invalid WKB: truncated buffer","messagePattern":"Invalid WKB: truncated buffer","errorType":"exception","errorClass":"Phalcon\\Db\\Exceptions\\InvalidWkb","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Geometry/WkbParser.zep","lineNumber":204,"sourceCode":"    }\n\n    protected function skipExtraOrdinates(bool little, bool hasZ, bool hasM) -> void\n    {\n        if hasZ {\n            this->readDouble(little);\n        }\n\n        if hasM {\n            this->readDouble(little);\n        }\n    }\n\n    protected function readByte() -> int\n    {\n        var arr;\n\n        if this->position + 1 > this->length {\n            throw new InvalidWkb(\"truncated buffer\");\n        }\n\n        let arr = unpack(\"C\", substr(this->buffer, this->position, 1)),\n            this->position = this->position + 1;\n\n        return (int) arr[1];\n    }\n\n    protected function readUint32(bool little) -> int\n    {\n        var fmt, arr;\n\n        if this->position + 4 > this->length {\n            throw new InvalidWkb(\"truncated buffer\");\n        }\n\n        let fmt = little ? \"V\" : \"N\",\n            arr = unpack(fmt, substr(this->buffer, this->position, 4)),","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Geometry/WkbParser.zep#L186-L222","documentation":"While walking the WKB buffer, WkbParser::readByte() needs 1 byte at the current position (byte-order markers, type codes, element counts). If fewer bytes remain it throws InvalidWkb('truncated buffer') — the payload ended earlier than its declared structure requires.","triggerScenarios":"A payload that declares more elements than bytes are present (e.g. a multi-geometry count followed by too few sub-geometries); a BLOB cut off mid-geometry; offsets shifted by mixing hex and binary interpretations of the same value.","commonSituations":"Interrupted inserts leaving truncated geometry values; manual substr() on geometry data; hand-crafted fixture strings with wrong lengths.","solutions":["Re-read the value from the database and compare byte length against the original before parsing","Fix or regenerate the stored geometry (re-export via ST_AsBinary) so the payload is complete","Catch InvalidWkb per row and skip bad records during batch processing"],"exampleFix":"// before\n$geom = $parser->parse($value); // may throw on truncated input\n\n// after\ntry {\n    $geom = $parser->parse($value);\n} catch (\\Phalcon\\Db\\Exceptions\\InvalidWkb $e) {\n    $logger->warning('truncated geometry rejected', ['value' => bin2hex($value)]);\n    $geom = null;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $geom = $parser->parse($raw);\n} catch (\\Phalcon\\Db\\Exceptions\\InvalidWkb $e) {\n    $geom = null; // payload shorter than its declared structure\n}","preventionTips":["Compare fetched byte length against the value the database reports before parsing","Never hand-edit or concatenate WKB strings to build fixtures","Wrap parse() in try/catch at the batch level so one bad row does not stop an import"],"tags":["wkb","geometry","phalcon-db","spatial","parser","truncated-data"],"backgroundTag":"invalid-wkb-payload","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}