Merge: 报表保真层残留2(maxResultBuffer结果集封顶)+残留4(逗号IN列表),73单测+JDBC探针+live全绿
Some checks failed
ci / build-test-parity (push) Has been cancelled
Some checks failed
ci / build-test-parity (push) Has been cancelled
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -61,6 +61,13 @@ public class JatoolsConfig {
|
||||
@Value("${eip4.report.db.socket-timeout-sec:35}")
|
||||
private int socketTimeoutSec;
|
||||
|
||||
/**
|
||||
* 报表查询的驱动结果集缓冲上限(pgjdbc maxResultBuffer,如 {@code 60p}=最大堆 60% / {@code 256m};空=不设)。
|
||||
* 引擎用 TYPE_SCROLL_INSENSITIVE 整集物化,无此上限时海量结果集可在产出前 OOM;设此值则超限抛异常而非 OOM。
|
||||
*/
|
||||
@Value("${eip4.report.db.max-result-buffer:60p}")
|
||||
private String maxResultBuffer;
|
||||
|
||||
/**
|
||||
* PDF 导出兜底字体(CJK 保真)候选路径,按序探测,取首个可加载者注册为
|
||||
* iText {@code DefaultFontMapper.defaultFont}。覆盖 macOS(本地验证)与常见 Linux 路径。
|
||||
@@ -96,8 +103,11 @@ public class JatoolsConfig {
|
||||
p.setProperty("font.dirs",
|
||||
"/System/Library/Fonts;/Library/Fonts;"
|
||||
+ "/usr/share/fonts;/usr/share/fonts/truetype;/usr/local/share/fonts");
|
||||
// 报表模板 <Connection> 解析到 EIP4 数据源(URL 追加 statement_timeout/socketTimeout 超时加固)
|
||||
String hardenedUrl = appendPgTimeouts(jdbcUrl == null ? "" : jdbcUrl, statementTimeoutMs, socketTimeoutSec);
|
||||
// 报表模板 <Connection> 解析到 EIP4 数据源:追加 statement_timeout/socketTimeout 超时加固
|
||||
// + maxResultBuffer 结果集缓冲上限(防全量物化 OOM)
|
||||
String hardenedUrl = appendPgResultBufferCap(
|
||||
appendPgTimeouts(jdbcUrl == null ? "" : jdbcUrl, statementTimeoutMs, socketTimeoutSec),
|
||||
maxResultBuffer);
|
||||
p.setProperty("DBJdbcUrl", hardenedUrl);
|
||||
p.setProperty("DBUser", dbUser == null ? "" : dbUser);
|
||||
p.setProperty("DBPassword", dbPassword == null ? "" : dbPassword);
|
||||
@@ -158,6 +168,22 @@ public class JatoolsConfig {
|
||||
* 仅作用于 {@code jdbc:postgresql} URL;已含同名参数则不重复(幂等);非正值则跳过对应项;
|
||||
* null/空/非 PG URL 原样返回。
|
||||
*/
|
||||
/**
|
||||
* 给 PostgreSQL JDBC URL 追加 pgjdbc {@code maxResultBuffer}(残留 2 收口):限制驱动为单条结果集
|
||||
* 缓冲的内存上限,超出即抛异常而非 OOM —— 对 jatools 引擎用的 {@code TYPE_SCROLL_INSENSITIVE}
|
||||
* (客户端整集物化)尤为关键。值如 {@code 60p}(占最大堆 60%)或 {@code 256m}。仅作用于
|
||||
* {@code jdbc:postgresql} URL;空值/已含同参/非 PG URL 原样返回。
|
||||
*/
|
||||
static String appendPgResultBufferCap(String url, String maxResultBuffer) {
|
||||
if (url == null || url.isBlank() || !url.startsWith("jdbc:postgresql")
|
||||
|| maxResultBuffer == null || maxResultBuffer.isBlank()
|
||||
|| url.contains("maxResultBuffer=")) {
|
||||
return url;
|
||||
}
|
||||
char sep = url.indexOf('?') >= 0 ? '&' : '?';
|
||||
return url + sep + "maxResultBuffer=" + maxResultBuffer.trim();
|
||||
}
|
||||
|
||||
static String appendPgTimeouts(String url, long statementTimeoutMs, int socketTimeoutSec) {
|
||||
if (url == null || url.isBlank() || !url.startsWith("jdbc:postgresql")) {
|
||||
return url;
|
||||
|
||||
@@ -48,8 +48,12 @@ public final class ReportParamGuard {
|
||||
private static final Pattern IDENT = Pattern.compile("[A-Za-z_][A-Za-z0-9_]*");
|
||||
/** 多字符危险子串:行注释 {@code --}、类型转换 {@code ::}(白名单已排除其它注释/星号字符)。 */
|
||||
private static final Pattern UNSAFE_SUBSTR = Pattern.compile("--|::");
|
||||
/** 除字母/数字(含 CJK)外允许的安全标点:ID/编码/日期所需。<strong>不含空格</strong>是挡住无引号注入的关键。 */
|
||||
private static final String EXTRA_SAFE_CHARS = "-_./:";
|
||||
/**
|
||||
* 除字母/数字(含 CJK)外允许的安全标点:ID/编码/日期/多值 IN 列表所需。
|
||||
* <strong>不含空格/括号/引号/等号</strong>是挡住无引号注入的关键;逗号安全(单独无法构成
|
||||
* UNION/子查询/注释/堆叠,后者均需空格/括号/引号/分号)。
|
||||
*/
|
||||
private static final String EXTRA_SAFE_CHARS = "-_./:,";
|
||||
|
||||
/**
|
||||
* 从模板文本里抽出所有在 {@code ${...}} 宏内出现过的标识符 token(自校准白名单)。
|
||||
|
||||
@@ -71,4 +71,33 @@ class JatoolsConfigUrlTest {
|
||||
assertEquals("", JatoolsConfig.appendPgTimeouts("", 5000, 30));
|
||||
assertEquals(null, JatoolsConfig.appendPgTimeouts(null, 5000, 30));
|
||||
}
|
||||
|
||||
// ---- maxResultBuffer:驱动层结果集缓冲上限,把「全量物化 OOM」变成「超限即抛」(残留 2 收口) ----
|
||||
|
||||
@Test
|
||||
void appends_max_result_buffer_with_existing_query() {
|
||||
String url = JatoolsConfig.appendPgResultBufferCap(
|
||||
"jdbc:postgresql://h/db?currentSchema=eip3", "60p");
|
||||
assertTrue(url.contains("currentSchema=eip3"), url);
|
||||
assertTrue(url.contains("maxResultBuffer=60p"), url);
|
||||
assertFalse(url.contains("??"), url);
|
||||
}
|
||||
|
||||
@Test
|
||||
void appends_max_result_buffer_with_question_mark_when_no_query() {
|
||||
String url = JatoolsConfig.appendPgResultBufferCap("jdbc:postgresql://h/db", "256m");
|
||||
assertEquals("jdbc:postgresql://h/db?maxResultBuffer=256m", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
void max_result_buffer_blank_or_nonpg_unchanged_and_idempotent() {
|
||||
assertEquals("jdbc:postgresql://h/db",
|
||||
JatoolsConfig.appendPgResultBufferCap("jdbc:postgresql://h/db", ""));
|
||||
assertEquals("jdbc:postgresql://h/db",
|
||||
JatoolsConfig.appendPgResultBufferCap("jdbc:postgresql://h/db", null));
|
||||
assertEquals("jdbc:oracle:thin:@h",
|
||||
JatoolsConfig.appendPgResultBufferCap("jdbc:oracle:thin:@h", "60p"));
|
||||
String once = JatoolsConfig.appendPgResultBufferCap("jdbc:postgresql://h/db", "60p");
|
||||
assertEquals(once, JatoolsConfig.appendPgResultBufferCap(once, "60p")); // 幂等
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,16 @@ class ReportParamGuardTest {
|
||||
assertFalse(ReportParamGuard.isSafeValue("1=1")); // 等号
|
||||
assertFalse(ReportParamGuard.isSafeValue("a b")); // 空格
|
||||
assertFalse(ReportParamGuard.isSafeValue("f(x)")); // 括号
|
||||
assertFalse(ReportParamGuard.isSafeValue("a,b")); // 逗号
|
||||
}
|
||||
|
||||
@Test
|
||||
void isSafeValue_allows_comma_lists_for_in_clause() {
|
||||
// 真实模板存在 in (${WELFARECATEGORYID})/in (${SCHEMEITEM}) 多值 IN 列表,需允许逗号。
|
||||
// 逗号本身无法构成注入:UNION/子查询/注释/堆叠仍需空格/括号/引号/分号(均被拒)。
|
||||
assertTrue(ReportParamGuard.isSafeValue("1,2,3"));
|
||||
assertTrue(ReportParamGuard.isSafeValue("a1b2,c3d4,e5f6"));
|
||||
assertFalse(ReportParamGuard.isSafeValue("1, 2")); // 逗号+空格仍拒
|
||||
assertFalse(ReportParamGuard.isSafeValue("1,(2)")); // 逗号+括号仍拒
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user