techfreakworm commited on
Commit
db233ed
·
unverified ·
1 Parent(s): b41947e

fix: bound uploads at launch — max_file_size from the LoRA ceiling, the one lever both sides read

Browse files

demo.launch() accepted uploads of any size. They land on gradio's tmp
disk BEFORE any check of ours can run — stage 1 of the LoRA validator
refuses oversized adapters by declared size without reading them, but it
never sees the request until gradio has already spooled it — and the
retention sweep covers outputs/ only, so nothing ever reclaims the space.
One request could fill the Space's disk.

The bound is CONFIG.lora_max_bytes * 1.05: the largest upload the app has
any use for is a LoRA at the validator's own ceiling (12 GB default;
conditioning media is orders of magnitude smaller), read off the CONFIG
so the LTX25_LORA_MAX_GB lever bounds both the validator and the
transport rather than drifting apart. The 5% margin covers multipart
framing, so a ceiling-sized adapter is refused by stage 1's message —
which names the limit and the actual size — instead of gradio's blunter
transport error.

Scope note: max_file_size is launch()'s only change; the GPU decoration
is untouched. The test pins presence, coverage of the ceiling, and that
the bound stays a bound (<= 2x ceiling).

Files changed (2) hide show
  1. app.py +13 -1
  2. tests/test_app.py +30 -0
app.py CHANGED
@@ -141,9 +141,21 @@ generate_module.set_gpu_dispatch(run_generation)
141
 
142
  demo = build_ui()
143
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
  def main() -> None:
146
- demo.launch()
147
 
148
 
149
  if __name__ == "__main__":
 
141
 
142
  demo = build_ui()
143
 
144
+ # The largest upload the app has any use for is a LoRA at the validator's own
145
+ # ceiling (config.lora_max_bytes; stage 1 refuses anything bigger BEFORE
146
+ # reading it) -- conditioning media is orders of magnitude smaller. Without a
147
+ # launch bound, any-size uploads land on gradio's tmp disk before any check of
148
+ # ours can run, and the retention sweep covers outputs/ only, so nothing ever
149
+ # reclaims that space. Reads the CONFIG, not the constant, so the
150
+ # LTX25_LORA_MAX_GB lever bounds both the validator and the transport. The
151
+ # 5% margin covers multipart framing so a ceiling-sized adapter is refused by
152
+ # the validator's stage 1 -- which names the limit and the actual size --
153
+ # rather than by gradio's blunter transport error.
154
+ MAX_UPLOAD_BYTES = int(CONFIG.lora_max_bytes * 1.05)
155
+
156
 
157
  def main() -> None:
158
+ demo.launch(max_file_size=MAX_UPLOAD_BYTES)
159
 
160
 
161
  if __name__ == "__main__":
tests/test_app.py CHANGED
@@ -140,3 +140,33 @@ def test_building_the_blocks_twice_is_safe():
140
  from ltx25_studio.ui import blocks
141
 
142
  assert blocks.build_ui() is not blocks.build_ui()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  from ltx25_studio.ui import blocks
141
 
142
  assert blocks.build_ui() is not blocks.build_ui()
143
+
144
+
145
+ def test_launching_bounds_the_upload_size(monkeypatch):
146
+ """Uploads land on gradio's tmp disk BEFORE any check of ours can run, and
147
+ the retention sweep covers outputs/ only -- so an unbounded launch lets one
148
+ request fill the disk with a file nothing ever reclaims. The bound must
149
+ cover the LoRA validator's own ceiling (the largest upload the app has a
150
+ use for) so a ceiling-sized adapter is refused by stage 1's message naming
151
+ the limit, not by gradio's blunter transport error -- and it must still BE
152
+ a bound, not a shrug."""
153
+ gradio = pytest.importorskip("gradio")
154
+ captured = {}
155
+ monkeypatch.setattr(
156
+ gradio.Blocks,
157
+ "launch",
158
+ lambda self, *a, **k: captured.update(k) or None,
159
+ raising=False,
160
+ )
161
+ sys.modules.pop("app", None)
162
+ module = importlib.import_module("app")
163
+ module.main()
164
+
165
+ from ltx25_studio.config import load_config
166
+
167
+ ceiling = load_config().lora_max_bytes
168
+ assert captured.get("max_file_size") is not None, (
169
+ "demo.launch() must pass max_file_size -- without it any-size uploads reach tmp disk"
170
+ )
171
+ assert captured["max_file_size"] >= ceiling
172
+ assert captured["max_file_size"] <= ceiling * 2