Conversation
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| def send_large_file(sock, path, tag, session_cipher, local_cipher, chunk_size=32768): | ||
| """Send large files (videos or generic files) in chunks.""" | ||
| filename = os.path.basename(path) | ||
| size = os.path.getsize(path) | ||
| send_encrypted(sock, f"{tag}START|{filename}|{size}", session_cipher, local_cipher) | ||
| with open(path, "rb") as f: | ||
| while chunk := f.read(chunk_size): | ||
| b64 = base64.b64encode(chunk).decode() | ||
| send_encrypted(sock, f"{tag}CHUNK|{filename}|{b64}", session_cipher, local_cipher) | ||
| send_encrypted(sock, f"{tag}END|{filename}", session_cipher, local_cipher) | ||
|
|
||
|
|
||
| def receive_messages(sock, session_cipher, local_cipher, history, state, expire_cb): | ||
| """Continuously receive and process messages from the peer.""" | ||
| ongoing = {} | ||
| try: | ||
| while True: | ||
| encrypted = sock.recv(65536) | ||
| if not encrypted: |
There was a problem hiding this comment.
[P1] Prevent partial reads for encrypted file chunks
Large media transfers encrypt a 32 KB chunk, base64 it, then encrypt twice with Fernet before sending. The resulting token is ~78 KB, which exceeds the 65 536 bytes read here. sock.recv(65536) may return only part of the token, causing session_cipher.decrypt to raise InvalidToken and the receiver thread to terminate, so video/file sends above ~25 KB will fail. Frame messages with a length prefix or loop until the full ciphertext is received (the same limit exists on the server side).
Useful? React with 👍 / 👎.
Summary
/emojicommands/nick/groupand restrict server broadcasts to members of the same groupTesting
python -m py_compile encrypted_chat/*.py build_exe.pypyflakes encrypted_chat/*.pyhttps://chatgpt.com/codex/tasks/task_e_68ba7a272ecc832b95275853cb750de6