Repository navigation
[Security] Cap GLMGA video sampling to prevent request-driven resource exhaustion #54935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -669,6 +669,9 @@ def load_bytes( | |
| video_processor="GlmgaVideoProcessor", | ||
| ) | ||
| class GLMGAVideoBackend(VideoBackend): | ||
| _MAX_FRAMES: ClassVar[int] = 640 | ||
| _MAX_FPS: ClassVar[int] = 30 | ||
|
|
||
| @classmethod | ||
| def _prepare_source(cls, source: VideoSourceMetadata) -> VideoSourceMetadata: | ||
| # Estimate duration from frame count and fps when the container | ||
|
|
@@ -694,14 +697,14 @@ def compute_frames_index_to_sample( | |
| total_frames_num = source.total_frames_num | ||
| duration = source.duration | ||
| original_fps = source.original_fps | ||
| target_fps = target.fps | ||
| target_fps = min(target.fps, cls._MAX_FPS) | ||
| max_frame_idx = source.total_frames_num - 1 | ||
| max_frames = kwargs.get("max_frames", 640) | ||
| max_frames = min(kwargs.get("max_frames", cls._MAX_FRAMES), cls._MAX_FRAMES) | ||
|
|
||
| duration = duration or round(max_frame_idx / original_fps) + 1 | ||
|
|
||
| extract_t = int(duration * target_fps) | ||
| extract_t = min(extract_t, max_frames) | ||
| extract_t = min(extract_t, max_frames, total_frames_num) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift Bound the intermediate index list. Line 819 limits Generate the final bounded index set directly when the natural sample count exceeds 🤖 Prompt for AI Agents |
||
|
|
||
| duration_per_frame = 1 / original_fps | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Make the FPS-cap test distinguish the FPS cap.
This test passes if the clamp on Line 812 is removed because
_MAX_FRAMESstill limits the result to 640. Use a source where 30 FPS produces fewer than 640 frames, such as a 10-second, 100-FPS source, and assert the expected 300 sampled indices. The uncapped 500,000-FPS path would then produce 640 indices.🤖 Prompt for AI Agents