{"record":{"id":"a6ff3976de9c7221","repo":"phalcon/cphalcon","slug":"invalid-wkb-unknown-geometry-type-basetype","errorCode":null,"errorMessage":"Invalid WKB: unknown geometry type {baseType}","messagePattern":"Invalid WKB: unknown geometry type (.+?)","errorType":"exception","errorClass":"Phalcon\\Db\\Exceptions\\InvalidWkb","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Geometry/WkbParser.zep","lineNumber":137,"sourceCode":"                        i       = i + 1;\n                }\n\n                if baseType === 4 {\n                    return new MultiPoint(items, srid);\n                }\n\n                if baseType === 5 {\n                    return new MultiLineString(items, srid);\n                }\n\n                if baseType === 6 {\n                    return new MultiPolygon(items, srid);\n                }\n\n                return new GeometryCollection(items, srid);\n\n            default:\n                throw new InvalidWkb(\"unknown geometry type \" . baseType);\n        }\n    }\n\n    protected function readPoint(bool little, bool hasZ, bool hasM, int srid) -> <Point>\n    {\n        var x, y;\n\n        let x = this->readDouble(little),\n            y = this->readDouble(little);\n\n        this->skipExtraOrdinates(little, hasZ, hasM);\n\n        return new Point(x, y, srid);\n    }\n\n    protected function readPointList(bool little, bool hasZ, bool hasM) -> array\n    {\n        var count, i, x, y, points = [];","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Geometry/WkbParser.zep#L119-L155","documentation":"After reading the geometry type code, WkbParser reduces it to a base type 1-7 (POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION). Any other value reaches the default branch and throws InvalidWkb('unknown geometry type N'), meaning the payload is corrupt or the bytes at the type position are not a WKB type code.","triggerScenarios":"Corrupt bytes stored in a geometry column; values that are neither hex nor MySQL-format WKB but survive the initial checks; offsets desynchronized from a wrong format detection so a coordinate byte is read as the type code.","commonSituations":"Application strings stored in a column later parsed as geometry; binary data damaged by UTF-8 conversion; vendor-specific encodings the parser does not understand.","solutions":["Verify the value at the source with the database's own functions (ST_AsBinary / ST_AsEWKB) and re-export the geometry","Skip or quarantine rows that fail to parse instead of aborting the batch","Confirm nothing transformed the value between fetch and parse (casts, serializers, JSON round-trips)"],"exampleFix":"// before\nforeach ($rows as $row) {\n    $geoms[] = $parser->parse($row['geom']);\n}\n\n// after\nforeach ($rows as $row) {\n    try {\n        $geoms[] = $parser->parse($row['geom']);\n    } catch (\\Phalcon\\Db\\Exceptions\\InvalidWkb $e) {\n        $bad[] = $row['id'];\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $geom = $parser->parse($raw);\n} catch (\\Phalcon\\Db\\Exceptions\\InvalidWkb $e) {\n    $badRows[] = $row['id']; // quarantine instead of aborting the batch\n    $geom = null;\n}","preventionTips":["Keep geometry columns out of reach of application string writes","Avoid encoding conversions (UTF-8, JSON) on binary geometry values","Re-validate stored geometries with the database's ST_* functions after bulk imports"],"tags":["wkb","geometry","phalcon-db","spatial","parser"],"backgroundTag":"invalid-wkb-payload","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}