Repository navigation
FIX: Fix CodeChameleonConverter decryption functions in binary_tree and length modes - #3165
Open
RohithPariki wants to merge 1 commit into
Open
RohithPariki wants to merge 1 commit into
RohithPariki wants to merge 1 commit into
Conversation
…nd length modes (fixes microsoft#3164)
Contributor
|
#3072 was technically here first but author didn't accept the CLA so happy to merge this. |
Roman Lutz (romanlutz)
approved these changes
Oct 13, 2026
Roman Lutz (romanlutz)
left a comment
Contributor
There was a problem hiding this comment.
I'll make a couple of improvements and then merge. Thank you!
This branch has not been deployed
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.
Description
Fixes #3164.
In
CodeChameleonConverter, the generated decryption functions forbinary_treeandlengthmodes contained bugs that caused runtime failures when executed:binary_treemode (_decrypt_binary_tree):string_to_treeusesjson.loads(problem_description), deserializing the full nested structure into Python dictionaries. The recursive helper then calledjson.loads(node_dict['left'])andjson.loads(node_dict['right']). Passing a Pythondicttojson.loads()resulted inTypeError: the JSON object must be str, bytes or bytearray, not dict.node_dict['left']andnode_dict['right']directly tohelper()without callingjson.loads.lengthmode (_decrypt_length):The
_encrypt_lengthmethod serializes the list of single-entry dictionaries to a JSON string (json.dumps(...)), which is inserted into the prompt template. However,decryption(encrypted_problem)did not importjsonor parseencrypted_problem. Iterating directly over the JSON string causedAttributeError: 'str' object has no attribute 'items'.import jsonand parsedencrypted_problemviajson.loadsif passed as a string.Tests and Documentation
tests/unit/converter/test_code_chameleon_converter.pyforbinary_treeandlengthmodes.test_codechameleon_converter_decryption_executionparametrized over all built-in encryption types (reverse,odd_even,binary_tree,length) to verify that the generateddecryption()function executes cleanly and reconstructs the original prompt.pytest tests/unit/converter/test_code_chameleon_converter.py(10/10 passed).ruff checkandruff format.