{"record":{"id":"d7196708c8444727","repo":"alibaba/Sentinel","slug":"size-of-file-s-exceeds-the-bufsize-d-d","errorCode":null,"errorMessage":"Size of file <%s> exceeds the bufSize (%d): %d","messagePattern":"Size of file <(.+?)> exceeds the bufSize \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileInJarReadableDataSource.java","lineNumber":100,"sourceCode":"        }\n        AssertUtil.notNull(charset, \"charset can't be null\");\n        this.buf = new byte[bufSize];\n        this.charset = charset;\n        this.jarName = jarName;\n        this.fileInJarName = fileInJarName;\n        initializeJar();\n        firstLoad();\n    }\n\n    @Override\n    public String readSource() throws Exception {\n        if (null == jarEntry) {\n            // Will throw FileNotFoundException later.\n            RecordLog.warn(String.format(\"[FileInJarReadableDataSource] File does not exist: %s\", jarFile.getName()));\n        }\n        try (InputStream inputStream = jarFile.getInputStream(jarEntry)) {\n            if (inputStream.available() > buf.length) {\n                throw new IllegalStateException(String.format(\"Size of file <%s> exceeds the bufSize (%d): %d\",\n                    jarFile.getName(), buf.length, inputStream.available()));\n            }\n            int len = inputStream.read(buf);\n            return new String(buf, 0, len, charset);\n        }\n    }\n\n    private void firstLoad() {\n        try {\n            T newValue = loadConfig();\n            getProperty().updateValue(newValue);\n        } catch (Throwable e) {\n            RecordLog.warn(\"[FileInJarReadableDataSource] Error when loading config\", e);\n        }\n    }\n\n    @Override\n    public void close() throws Exception {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileInJarReadableDataSource.java#L82-L118","documentation":"FileInJarReadableDataSource.readSource() opens the jar entry and checks inputStream.available() against the fixed buffer allocated at construction. If the in-jar file is larger than bufSize, reading it into the single buffer would truncate the config, so it throws IllegalStateException naming the file, buffer size, and actual size.","triggerScenarios":"readSource()/firstLoad() when the target file inside the jar grew beyond bufSize — typical after a jar rebuild added more rules, while the datasource was constructed with a small explicit bufSize or after fat-jar repackaging.","commonSituations":"Constructing with a tight bufSize (e.g. 4 KB) that fit at first, then the config file grows in a later release; misjudging available() semantics for compressed jar entries (it can under-report but the check still fires when over).","solutions":["Increase bufSize at construction to at least the largest expected file size (bounded by MAX_SIZE).","Or use the default constructor size (1 MB) which covers most rule files.","Verify the actual in-jar file size: unzip -l app.jar | grep <fileInJarName> and compare with bufSize in the error message."],"exampleFix":"// before\nnew FileInJarReadableDataSource<>(jar, name, parser, 4096, charset);\n// rules.json grew past 4KB -> IllegalStateException on readSource\n\n// after\nnew FileInJarReadableDataSource<>(jar, name, parser, 1024 * 1024, charset);","handlingStrategy":"validation","validationCode":"// Size the buffer from the actual entry before constructing\ntry (JarFile jf = new JarFile(new File(jarName))) {\n    int size = (int) jf.getInputStream(jf.getJarEntry(fileInJarName)).available();\n    bufSize = Math.max(size, 4096);\n} // then construct with bufSize (<= MAX_SIZE)","typeGuard":null,"tryCatchPattern":"try {\n    return ds.readSource();\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"exceeds the bufSize\")) {\n        // rebuild datasource with larger bufSize (file grew in new build)\n        ds = rebuildWithLargerBuffer();\n        return ds.readSource();\n    }\n    throw e;\n}","preventionTips":["Track the in-jar config file size in CI and alert when it approaches bufSize.","Default to the 1MB buffer unless memory constraints forbid it."],"tags":["sentinel","datasource","jar","buffer-overflow","config"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}