{"record":{"id":"962b159808a9f2bf","repo":"elastic/elasticsearch","slug":"database-type-marker-not-found","errorCode":null,"errorMessage":"database type marker not found","messagePattern":"database type marker not found","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"modules/ip-location/src/main/java/org/elasticsearch/ingest/geoip/MMDBUtil.java","lineNumber":76,"sourceCode":"            // find the database_type header\n            int metadataOffset = -1;\n            int markerOffset = 0;\n            for (int i = 0; i < tail.length; i++) {\n                byte b = tail[i];\n\n                if (b == DATABASE_TYPE_MARKER[markerOffset]) {\n                    markerOffset++;\n                } else {\n                    markerOffset = 0;\n                }\n                if (markerOffset == DATABASE_TYPE_MARKER.length) {\n                    metadataOffset = i + 1;\n                    break;\n                }\n            }\n\n            if (metadataOffset == -1) {\n                throw new IOException(\"database type marker not found\");\n            }\n\n            // read the database type\n            final int offsetByte = fromBytes(tail[metadataOffset]);\n            final int type = offsetByte >>> 5;\n            if (type != 2) { // 2 is the type indicator in the mmdb format for a UTF-8 string\n                throw new IOException(\"type must be UTF-8 string\");\n            }\n            int size = offsetByte & 0x1f;\n            if (size == 29) {\n                // then we need to read in yet another byte and add it onto this size\n                // this can actually occur in practice, a 29+ character type description isn't that hard to imagine\n                size = 29 + fromBytes(tail[metadataOffset + 1]);\n                metadataOffset += 1;\n            } else if (size >= 30) {\n                // we'd need to read two or three more bytes to get the size, but this means the type length is >=285\n                throw new IOException(\"database_type too long [size indicator == \" + size + \"]\");\n            }","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ip-location/src/main/java/org/elasticsearch/ingest/geoip/MMDBUtil.java#L58-L94","documentation":"Thrown by MMDBUtil.getDatabaseType when the DATABASE_TYPE_MARKER byte sequence is not found within the last BUFFER_SIZE bytes of the file. The marker locates the database_type metadata field in the mmdb tail; its absence means the file is not a valid mmdb or is badly corrupted. IOException propagates to the lookup wiring path.","triggerScenarios":"getDatabaseType scans tail[] for DATABASE_TYPE_MARKER; markerOffset never reaches the marker length; metadataOffset stays -1 -> throw.","commonSituations":"A non-mmdb file supplied as a geoip database; a corrupt/truncated mmdb missing its metadata section; a gzipped file that was not decompressed before reading; BUFFER_SIZE smaller than the metadata section (very large metadata).","solutions":["Confirm the file is an mmdb and not still gzipped (use MMDBUtil.isGzip or a manual gunzip check).","Re-download the database to rule out truncation.","Validate the file with the official mmdblookup tool.","If metadata is unusually large, review whether BUFFER_SIZE needs increasing (code change)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"boolean looksLikeMmdb(Path p) throws IOException {\n    if (MMDBUtil.isGzip(p)) return false; // still gzipped, not readable as mmdb\n    long size = Files.size(p);\n    if (size == 0) return false;\n    // best-effort: tail must contain the database type marker\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n    String type = MMDBUtil.getDatabaseType(path);\n} catch (IOException e) {\n    if (e.getMessage().equals(\"database type marker not found\")) {\n        // file is not a valid mmdb; re-download or gunzip first\n    } else throw e;\n}","preventionTips":["Decompress gzipped downloads before reading as mmdb.","Validate the file with mmdblookup before loading.","Re-download on truncation.","Reject non-mmdb files at ingest configuration time."],"tags":["geoip","mmdb","data-integrity","metadata","corruption"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}