paramiko / paramiko/paramiko

Ability to ignore unidcode decode errors.

Open
#1,443 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9.9k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

I ran on a issue today where I as trying to read a File object from a malformed utf-8 string with an invalid character. I managed to fix my issue creating my own readlines() function with a try/catch block, but I don't think this solution is resistant to future updates from this libary since I cant' guarantee that the file cursor will move to the next line before this error occur.

def readlines(file):
  lines = []
  eof = False
  while not eof:
    try:
      line = file.readline()
      if line == '':
        eof = True
      else:
        lines.append(line)
    except UnicodeDecodeError as e:
      lines.append(e.object.decode('utf-8',errors='replace'))
  return lines

One simple solution to this would be adding a default error handling in line 68.

https://github.com/paramiko/paramiko/blob/cf7d49d66f3b1fbc8b0853518a54050182b3b5eb/paramiko/py3compat.py#L60-L71

changing to

return s.decode(encoding, errors='replace')

or even better giving the user the choice of how she/he would handle the errors via an optional argument.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in py3compat.py around lines 60–71, then reproduce the malformed UTF-8 File.readline case described in the issue. Review how decoding errors are currently surfaced and determine the intended replacement-versus-configurable behavior; done means the chosen handling is documented and the malformed-input behavior is covered by validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.