fix profile with older keys being reported as corrupt

Older Anki versions like 2.1.35 used sip 5.2, which appears to
(presumably incorrectly) serialize QByteArrays as Unicode:

    0: (    MARK
    1: d        DICT       (MARK at 0)
    2: p    PUT        0
    5: V    UNICODE    'mainWindowGeom'
   21: p    PUT        1
   24: c    GLOBAL     'sip _unpickle_type'
   44: p    PUT        2
   47: (    MARK
   48: V        UNICODE    'PyQt5.QtCore'
   62: p        PUT        3
   65: V        UNICODE    'QByteArray'
   77: p        PUT        4
   80: (        MARK
   81: c            GLOBAL     '_codecs encode'
   97: p            PUT        5
  100: (            MARK
  101: V                UNICODE    "[...]"
  354: p                PUT        6
  357: V                UNICODE    'latin1'
  365: p                PUT        7
  368: t                TUPLE      (MARK at 100)

Our unpickle_type() was incorrectly ignoring any non-PyQt class when
unpickling, so it was choking on the reference to _codecs.
This commit is contained in:
Damien Elmes 2021-11-06 09:32:23 +10:00
parent 371f731e30
commit 5a9a03e65a

View File

@ -184,6 +184,8 @@ class ProfileManager:
return sip._unpickle_type(module, klass, args) # type: ignore
return unpickle_type
else:
return super().find_class(class_module, name)
up = Unpickler(io.BytesIO(data), errors="ignore")
return up.load()
@ -204,12 +206,12 @@ class ProfileManager:
try:
self.profile = self._unpickle(data)
except:
print(traceback.format_exc())
QMessageBox.warning(
None,
tr.profiles_profile_corrupt(),
tr.profiles_anki_could_not_read_your_profile(),
)
traceback.print_stack()
print("resetting corrupt profile")
self.profile = profileConf.copy()
self.save()