Repository navigation
Conversation
model/model.py and visualizer.py parse the <|det|>[[x1, y1, x2, y2]]<|/det|> coordinates, and visualizer.py also the geometry dict, with eval(). That text is produced by the model and depends on the input document, so it should be treated as untrusted. Only Python literals are needed, and literal_eval() parses them without evaluating expressions. Valid coordinates parse to the same values as before. Text that is not a literal now raises ValueError and goes through the existing error handling. Assisted-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
In
deepseek-ocr/, replaceeval()withast.literal_eval()where text produced by the model is parsed:model/model.py:extract_coordinates_and_labelvisualizer.py:extract_coordinates_and_labeland the geometry (Line/Circle) parsingIt is imported as
from ast import literal_evalso the longest changed line stays within ruff-format's 88 columns. No other changes.Why
The model's output depends on the input document, so it is untrusted input, and
model.pyruns on the serving side. These spots only need lists, tuples, numbers and strings, whichliteral_evalparses without evaluating expressions. Text that isn't a literal now raisesValueErrorand takes the existingtry/exceptpath, as malformed coordinates already do.Testing
No model or GPU needed. I loaded
extract_coordinates_and_label(both files) and theDeepSeekOCRVisualizerclass from the original and the patched files into a small script (Python 3.12, Pillow 12.3) and compared them:[[10, 20, 30, 40]],[10, 20, 30, 40], several boxes, floats/negatives, tuples and non-list literals return the same values as before.draw_bounding_boxesproduces a byte-identical image.extract_coordinates_and_labelreturnsNonethrough its existingexceptbranch and that box is skipped.I did not deploy the Truss or run ruff locally (checked line lengths by hand).
Prepared with help from Claude (AI), including the local test described above.