Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

Fix PR #4805 review issues in XLSX, PPTX, and CLI policy code

myhlolic8ca212a4fe4
diff --git a/mineru/backend/utils/office_chart.py b/mineru/backend/utils/office_chart.py
index bd535fcb..9c016c23 100644
--- a/mineru/backend/utils/office_chart.py
+++ b/mineru/backend/utils/office_chart.py
@@ -1,3 +1,4 @@
+# Copyright (c) Opendatalab. All rights reserved.
import re
from io import BytesIO
diff --git a/mineru/cli/fast_api.py b/mineru/cli/fast_api.py
index da8e01ac..b7aa24ee 100644
--- a/mineru/cli/fast_api.py
+++ b/mineru/cli/fast_api.py
@@ -44,6 +44,13 @@ from mineru.cli.common import (
read_fn,
uniquify_task_stems,
)
+from mineru.cli.public_http_client_policy import (
+ PUBLIC_HTTP_CLIENT_DISABLED_DETAIL,
+ configure_public_http_client_policy,
+ is_public_bind_host,
+ validate_public_http_client_request,
+ warn_if_public_http_client_policy as _warn_if_public_http_client_policy,
+)
from mineru.cli.output_paths import resolve_parse_dir
from mineru.cli.api_protocol import (
API_PROTOCOL_VERSION,
@@ -86,11 +93,6 @@ FILE_PARSE_TASK_STATUS_URL_HEADER = "X-MinerU-Task-Status-Url"
FILE_PARSE_TASK_RESULT_URL_HEADER = "X-MinerU-Task-Result-Url"
MINERU_API_PUBLIC_BIND_EXPOSED_ENV = "MINERU_API_PUBLIC_BIND_EXPOSED"
MINERU_API_ALLOW_PUBLIC_HTTP_CLIENT_ENV = "MINERU_API_ALLOW_PUBLIC_HTTP_CLIENT"
-PUBLIC_HTTP_CLIENT_DISABLED_DETAIL = (
- "Publicly exposed API disables *-http-client backends and server_url by "
- "default. Rebind to 127.0.0.1 or start with "
- "--allow-public-http-client if you understand the SSRF risk."
-)
SWAGGER_UI_FILE_ARRAY_SCHEMA_EXTRA = {
# Swagger UI 5 currently fails to render a usable multi-file picker when
# FastAPI emits OpenAPI 3.1 byte arrays with contentMediaType.
@@ -362,51 +364,11 @@ def get_output_root() -> Path:
return root.resolve()
-def is_public_bind_host(host: str) -> bool:
- return host in {"0.0.0.0", "::"}
-
-
-def configure_public_http_client_policy(
- app: FastAPI,
- *,
- public_bind_exposed: bool,
- allow_public_http_client: bool,
-) -> None:
- app.state.public_bind_exposed = public_bind_exposed
- app.state.allow_public_http_client = allow_public_http_client
-
-
-def validate_public_http_client_request(
- *,
- public_bind_exposed: bool,
- allow_public_http_client: bool,
- backend: str,
- server_url: str | None,
-) -> None:
- if not public_bind_exposed or allow_public_http_client:
- return
- if backend.endswith("-http-client") or bool(server_url and server_url.strip()):
- raise HTTPException(status_code=400, detail=PUBLIC_HTTP_CLIENT_DISABLED_DETAIL)
-
-
def warn_if_public_http_client_policy(host: str, allow_public_http_client: bool) -> None:
- if not is_public_bind_host(host):
- return
- if allow_public_http_client:
- logger.warning(
- "MinerU API is listening on {} with --allow-public-http-client enabled. "
- "Requests may supply remote HTTP inference endpoints and turn the service "
- "into an externally driven outbound request primitive, creating SSRF and "
- "internal network probing risk.",
- host,
- )
- return
- logger.warning(
- "MinerU API is listening on {}. Disabling *-http-client backends and "
- "server_url by default because these inputs let callers choose remote HTTP "
- "inference endpoints; when the API is publicly reachable, that creates SSRF "
- "and internal network probing risk.",
- host,
+ _warn_if_public_http_client_policy(
+ service_name="API",
+ host=host,
+ allow_public_http_client=allow_public_http_client,
)
diff --git a/mineru/cli/public_http_client_policy.py b/mineru/cli/public_http_client_policy.py
new file mode 100644
index 00000000..e1442030
--- /dev/null
+++ b/mineru/cli/public_http_client_policy.py
@@ -0,0 +1,65 @@
+# Copyright (c) Opendatalab. All rights reserved.
+from fastapi import FastAPI, HTTPException
+from loguru import logger
+
+
+PUBLIC_HTTP_CLIENT_DISABLED_DETAIL = (
+ "Publicly exposed API disables *-http-client backends and server_url by "
+ "default. Rebind to 127.0.0.1 or start with "
+ "--allow-public-http-client if you understand the SSRF risk."
+)
+
+
+def is_public_bind_host(host: str) -> bool:
+ return host in {"0.0.0.0", "::"}
+
+
+def configure_public_http_client_policy(
+ app: FastAPI,
+ *,
+ public_bind_exposed: bool,
+ allow_public_http_client: bool,
+) -> None:
+ app.state.public_bind_exposed = public_bind_exposed
+ app.state.allow_public_http_client = allow_public_http_client
+
+
+def validate_public_http_client_request(
+ *,
+ public_bind_exposed: bool,
+ allow_public_http_client: bool,
+ backend: str,
+ server_url: str | None,
+) -> None:
+ if not public_bind_exposed or allow_public_http_client:
+ return
+ if backend.endswith("-http-client") or bool(server_url and server_url.strip()):
+ raise HTTPException(status_code=400, detail=PUBLIC_HTTP_CLIENT_DISABLED_DETAIL)
+
+
+def warn_if_public_http_client_policy(
+ *,
+ service_name: str,
+ host: str,
+ allow_public_http_client: bool,
+) -> None:
+ if not is_public_bind_host(host):
+ return
+ if allow_public_http_client:
+ logger.warning(
+ "MinerU {} is listening on {} with --allow-public-http-client enabled. "
+ "Requests may supply remote HTTP inference endpoints and turn the service "
+ "into an externally driven outbound request primitive, creating SSRF and "
+ "internal network probing risk.",
+ service_name,
+ host,
+ )
+ return
+ logger.warning(
+ "MinerU {} is listening on {}. Disabling *-http-client backends and "
+ "server_url by default because these inputs let callers choose remote HTTP "
+ "inference endpoints; when the API is publicly reachable, that creates SSRF "
+ "and internal network probing risk.",
+ service_name,
+ host,
+ )
diff --git a/mineru/cli/router.py b/mineru/cli/router.py
index 5be8c07d..fca51d09 100644
--- a/mineru/cli/router.py
+++ b/mineru/cli/router.py
@@ -40,6 +40,13 @@ from mineru.cli.api_client import (
)
from mineru.cli.api_protocol import API_PROTOCOL_VERSION
from mineru.cli.common import normalize_upload_filename
+from mineru.cli.public_http_client_policy import (
+ PUBLIC_HTTP_CLIENT_DISABLED_DETAIL,
+ configure_public_http_client_policy,
+ is_public_bind_host,
+ validate_public_http_client_request,
+ warn_if_public_http_client_policy as _warn_if_public_http_client_policy,
+)
from mineru.cli.vlm_preload import build_local_api_cli_args
from mineru.version import __version__
@@ -66,11 +73,6 @@ WORKER_REFRESH_INTERVAL_SECONDS = 2.0
MIN_HEALTHY_PROCESSING_WINDOW_SIZE = 1
MINERU_ROUTER_PUBLIC_BIND_EXPOSED_ENV = "MINERU_ROUTER_PUBLIC_BIND_EXPOSED"
MINERU_ROUTER_ALLOW_PUBLIC_HTTP_CLIENT_ENV = "MINERU_ROUTER_ALLOW_PUBLIC_HTTP_CLIENT"
-PUBLIC_HTTP_CLIENT_DISABLED_DETAIL = (
- "Publicly exposed API disables *-http-client backends and server_url by "
- "default. Rebind to 127.0.0.1 or start with "
- "--allow-public-http-client if you understand the SSRF risk."
-)
def utc_now_iso() -> str:
@@ -127,51 +129,11 @@ def is_task_terminal(status: str) -> bool:
return status in TASK_TERMINAL_STATES
-def is_public_bind_host(host: str) -> bool:
- return host in {"0.0.0.0", "::"}
-
-
-def configure_public_http_client_policy(
- app: FastAPI,
- *,
- public_bind_exposed: bool,
- allow_public_http_client: bool,
-) -> None:
- app.state.public_bind_exposed = public_bind_exposed
- app.state.allow_public_http_client = allow_public_http_client
-
-
-def validate_public_http_client_request(
- *,
- public_bind_exposed: bool,
- allow_public_http_client: bool,
- backend: str,
- server_url: str | None,
-) -> None:
- if not public_bind_exposed or allow_public_http_client:
- return
- if backend.endswith("-http-client") or bool(server_url and server_url.strip()):
- raise HTTPException(status_code=400, detail=PUBLIC_HTTP_CLIENT_DISABLED_DETAIL)
-
-
def warn_if_public_http_client_policy(host: str, allow_public_http_client: bool) -> None:
- if not is_public_bind_host(host):
- return
- if allow_public_http_client:
- logger.warning(
- "MinerU router is listening on {} with --allow-public-http-client enabled. "
- "Requests may supply remote HTTP inference endpoints and turn the service "
- "into an externally driven outbound request primitive, creating SSRF and "
- "internal network probing risk.",
- host,
- )
- return
- logger.warning(
- "MinerU router is listening on {}. Disabling *-http-client backends and "
- "server_url by default because these inputs let callers choose remote HTTP "
- "inference endpoints; when the API is publicly reachable, that creates SSRF "
- "and internal network probing risk.",
- host,
+ _warn_if_public_http_client_policy(
+ service_name="router",
+ host=host,
+ allow_public_http_client=allow_public_http_client,
)
diff --git a/mineru/model/pptx/pptx_converter.py b/mineru/model/pptx/pptx_converter.py
index 70273e0a..fd25d888 100644
--- a/mineru/model/pptx/pptx_converter.py
+++ b/mineru/model/pptx/pptx_converter.py
@@ -810,22 +810,18 @@ class PptxConverter:
run,
paragraph_font_sources: list[etree._Element],
) -> Optional[str]:
- """从PPTX run对象提取可序列化的显式字体样式字符串。"""
+ """从PPTX run对象提取可序列化的生效字体样式字符串。"""
if run is None:
return None
- run_rpr = self._get_run_rpr(run)
- if run_rpr is None:
- return None
-
styles = []
- if self._parse_bold_from_rpr(run_rpr) is True:
+ if self._resolve_effective_run_bold(run, paragraph_font_sources):
styles.append("bold")
- if self._parse_italic_from_rpr(run_rpr) is True:
+ if self._resolve_effective_run_italic(run, paragraph_font_sources):
styles.append("italic")
- if self._parse_underline_from_rpr(run_rpr) is True:
+ if self._resolve_effective_run_underline(run, paragraph_font_sources):
styles.append("underline")
- if self._parse_strikethrough_from_rpr(run_rpr) is True:
+ if self._resolve_effective_run_strikethrough(run, paragraph_font_sources):
styles.append("strikethrough")
return ",".join(styles) if styles else None
@@ -1282,7 +1278,7 @@ class PptxConverter:
self,
run,
paragraph_font_sources: list[etree._Element],
- ) -> Optional[bool]:
+ ) -> bool:
return self._resolve_effective_run_bool(
run,
paragraph_font_sources,
diff --git a/mineru/model/xlsx/xlsx_converter.py b/mineru/model/xlsx/xlsx_converter.py
index deffb8e2..3b5a4c94 100644
--- a/mineru/model/xlsx/xlsx_converter.py
+++ b/mineru/model/xlsx/xlsx_converter.py
@@ -115,6 +115,7 @@ class XlsxConverter:
self.cell_image_map = {}
self.sheet_images = []
self.table_image_map = {}
+ self.math_map = {}
self.equation_bookends: str = "<eq>{EQ}</eq>" # 公式标记格式
def convert(
@@ -415,6 +416,16 @@ class XlsxConverter:
)
return None
+ if not all(
+ isinstance(bound, int)
+ for bound in (min_col, min_row, max_col, max_row)
+ ):
+ logger.debug(
+ "Skip chart reference formula with open-ended bounds: {}",
+ formula,
+ )
+ return None
+
rows = list(range(min_row - 1, max_row))
cols = list(range(min_col - 1, max_col))
return rows, cols