Use ast.literal_eval instead of eval in hellaswag_arabic_pfn#1294
Open
jayzuccarelli wants to merge 1 commit into
Open
Use ast.literal_eval instead of eval in hellaswag_arabic_pfn#1294jayzuccarelli wants to merge 1 commit into
jayzuccarelli wants to merge 1 commit into
Conversation
The endings field comes from a community dataset on the Hub; eval() executes arbitrary Python from it. ast.literal_eval parses the same string-encoded lists safely and raises on anything else, matching how other tasks already parse such fields. Fixes huggingface#1293
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.
Fixes #1293
hellaswag_arabic_pfn(thehellaswag_okapi_arprompt function) parsedline["endings"]with the builtineval(). That field is a string-encoded list coming from theOALL/AlGhafa-Arabic-LLM-Benchmark-Translateddataset on the Hub, so a crafted value would execute arbitrary code on the machine running the eval.This switches it to
ast.literal_eval(), which parses the same string-encoded lists and raisesValueErroron anything that is not a plain literal. It's also the pattern already used elsewhere in the codebase for string-encoded dataset fields (e.g.sacrebleu.py). A repo-wide grep shows this was the only remainingeval()on dataset content.Tests added in
tests/unit/tasks/test_arabic_tasks.py:Doc(choices/gold_index)endingsraisesValueErrorinstead of executing — this test fails onmain(the payload runs) and passes with this changepytest tests/unit/tasks/test_arabic_tasks.py: 2 passed.ruff checkandruff format --checkclean on both touched files.