Skip to content

Commit d8d7bec

Browse files
committed
fix and improvement
1 parent f0f74ca commit d8d7bec

8 files changed

Lines changed: 27 additions & 15 deletions

File tree

app_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from database import ( # noqa: F401
2525
get_db, close_db, save_task_status, record_task_history, _build_task_note,
2626
get_score_data_by_ids, load_map_projection, get_task_info_from_db, get_tracks_by_ids,
27-
save_track_analysis_and_embedding, save_clap_embedding, get_clap_embedding, save_lyrics_embedding,
27+
save_track_analysis_and_embedding,
2828
# Used internally by the build_and_store_* projection orchestration below.
2929
save_map_projection, save_artist_projection,
3030
)

app_logging.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@
5050
"]+"
5151
)
5252

53-
# C0 control codes plus DEL, EXCEPT tab (0x09). Includes LF (0x0A) and CR (0x0D):
54-
# replacing these with a space prevents a value with embedded newlines from
55-
# forging additional log lines.
56-
_CONTROL_RE = re.compile(r"[\x00-\x08\x0A-\x1F\x7F]")
53+
# Control codes plus DEL and the Unicode line/paragraph separators, EXCEPT tab
54+
# (0x09). Includes LF (0x0A), CR (0x0D), NEL (U+0085), LINE SEPARATOR (U+2028)
55+
# and PARAGRAPH SEPARATOR (U+2029): replacing these with a space prevents a
56+
# value with an embedded line break from forging additional log lines, including
57+
# for consumers (and Windows code-pages) that treat the Unicode separators as
58+
# line boundaries.
59+
_CONTROL_RE = re.compile(r"[\x00-\x08\x0A-\x1F\x7F\x85" + chr(0x2028) + chr(0x2029) + "]")
5760

5861

5962
def _sanitize_log_text(text: Any) -> Any:

app_provider_migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __getattr__(self, name):
6666

6767
# ---------------------------------------------------------------------------
6868
# SSRF guard for the user-supplied media-server URL. Delegates to the shared
69-
# ``app_helper.validate_outbound_url`` (allows LAN/loopback, blocks non-HTTP(S)
69+
# ``ssrf_guard.validate_outbound_url`` (allows LAN/loopback, blocks non-HTTP(S)
7070
# schemes and link-local/cloud-metadata). A missing url is allowed and left to
7171
# the downstream probe.
7272
# ---------------------------------------------------------------------------

sanitization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def sanitize_for_json(obj):
103103
# Handle numpy numeric types which are not JSON serializable by default
104104
elif isinstance(obj, (np.int_, np.intc, np.intp, np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64)):
105105
return int(obj)
106-
elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)):
106+
elif isinstance(obj, np.floating):
107107
return float(obj)
108108
elif isinstance(obj, np.bool_):
109109
return bool(obj)

tasks/ai/providers/openai.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,12 @@ def call_with_tools_ollama(
512512
valid_calls = []
513513
for tc in tool_calls:
514514
if isinstance(tc, dict) and "name" in tc:
515-
if "arguments" not in tc or not isinstance(tc["arguments"], dict):
515+
if "arguments" not in tc:
516+
tc["arguments"] = {}
517+
elif not isinstance(tc["arguments"], dict):
518+
log_messages.append(
519+
f"Coerced non-dict arguments for tool '{tc['name']}' to empty dict"
520+
)
516521
tc["arguments"] = {}
517522
args = tc["arguments"]
518523
keys_to_remove = []

tasks/clustering.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@
6464
select_top_n_diverse_playlists
6565
)
6666

67-
# we want to maintain np.float_ for backwards compatibility but it was removed in numpy 2.0
68-
# the check below in sanitize_for_json causes an AttributeError that crashes the clustering algo
69-
# since it tries to access np.float_ so we monkeypatch np.float_ to point to np.float64
70-
if not np.__dict__.get('float_'):
71-
np.float_ = np.float64
72-
7367
logger = logging.getLogger(__name__)
7468

7569
def batch_task_failure_handler(job, connection, type, value, tb):

test/unit/test_app_logging.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ def test_crlf_collapses_to_single_space(self):
3131
def test_control_chars_become_space(self):
3232
assert _sanitize_log_text("a\x00b\x07c\x7f") == "a b c"
3333

34+
def test_unicode_line_separators_become_space(self):
35+
for sep in (chr(0x85), chr(0x2028), chr(0x2029)):
36+
assert _sanitize_log_text("a" + sep + "b") == "a b"
37+
38+
def test_unicode_separator_cannot_forge_a_line(self):
39+
forged = "user42" + chr(0x2028) + "[INFO]-[fake]-dropped all tables"
40+
result = _sanitize_log_text(forged)
41+
assert all(sep not in result for sep in (chr(0x85), chr(0x2028), chr(0x2029)))
42+
assert len(result.splitlines()) == 1
43+
3444
def test_tab_is_preserved(self):
3545
assert _sanitize_log_text("col1\tcol2") == "col1\tcol2"
3646

test/unit/test_provider_migration_blueprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def test_happy_path_enqueues_job(self, bp_mod, client, fake_db):
345345

346346
# ---------------------------------------------------------------------------
347347
# SSRF guard on the user-supplied media-server URL (_validate_probe_url ->
348-
# app_helper.validate_outbound_url). Self-hosted servers live on the LAN /
348+
# ssrf_guard.validate_outbound_url). Self-hosted servers live on the LAN /
349349
# loopback, so those are accepted; cloud-metadata, link-local, multicast,
350350
# unspecified and non-HTTP(S) schemes are rejected. IP literals are used so the
351351
# checks never depend on DNS resolution.

0 commit comments

Comments
 (0)