# Buggy code
def ReadPair(self, parser_mediator, file_object):
    """Reads an attribute name and value pair from a CUPS IPP event.

    Args:
      parser_mediator: A parser mediator object (instance of ParserMediator).
      file_object: a file-like object that points to a file.

    Returns:
      A list of name and value. If name and value cannot be read both are
      set to None.
    """
    # Pair = Type ID + Name + Value.
    try:
        # Can be:
        #   Group ID + IDtag = Group ID (1byte) + Tag ID (1byte) + '0x00'.
        #   IDtag = Tag ID (1byte) + '0x00'.
        type_id = self.INTEGER_8.parse_stream(file_object)
        if type_id == self.GROUP_END:
            return None, None

        elif type_id in self.GROUP_LIST:
            # If it is a group ID we must read the next byte that contains
            # the first TagID.
            type_id = self.INTEGER_8.parse_stream(file_object)

        # 0x00 separator character.
        _ = self.INTEGER_8.parse_stream(file_object)

    except (IOError, construct.FieldError):
        logging.warning(
            "[{0:s}] Unsupported identifier in file: {1:s}.".format(
                self.NAME, parser_mediator.GetDisplayName()
            )
        )
        return None, None

    # Name = Length name + name + 0x00
    try:
        name = self.PAIR_NAME.parse_stream(file_object).text
    except (IOError, construct.FieldError):
        logging.warning(
            "[{0:s}] Unsupported name in file: {1:s}.".format(
                self.NAME, parser_mediator.GetDisplayName()
            )
        )
        return None, None

    # Value: can be integer, boolean or text select by Type ID.
    try:
        if type_id in [
            self.TYPE_GENERAL_INTEGER,
            self.TYPE_INTEGER,
            self.TYPE_ENUMERATION,
        ]:
            value = self.INTEGER.parse_stream(file_object).integer

        elif type_id == self.TYPE_BOOL:
            value = bool(self.BOOLEAN.parse_stream(file_object).integer)

        elif type_id == self.TYPE_DATETIME:
            datetime = self.DATETIME.parse_stream(file_object)
            value = timelib.Timestamp.FromRFC2579Datetime(
                datetime.year,
                datetime.month,
                datetime.day,
                datetime.hour,
                datetime.minutes,
                datetime.seconds,
                datetime.deciseconds,
                datetime.direction_from_utc,
                datetime.hours_from_utc,
                datetime.minutes_from_utc,
            )

        else:
            value = self.TEXT.parse_stream(file_object)

    except (IOError, UnicodeDecodeError, construct.FieldError):
        logging.warning(
            "[{0:s}] Unsupported value in file: {1:s}.".format(
                self.NAME, parser_mediator.GetDisplayName()
            )
        )
        return None, None

    return name, value


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "plaso/multi_processing/multi_process.py", line 1214, in _ProcessTask
self._parser_mediator, task.path_spec)
File "plaso/engine/worker.py", line 618, in ProcessPathSpec
self._ProcessFileEntry(parser_mediator, file_entry)
File "plaso/engine/worker.py", line 452, in _ProcessFileEntry
parser_mediator, file_entry, data_stream.name)
File "plaso/engine/worker.py", line 543, in _ProcessFileEntryDataStream
parser_mediator, file_entry, data_stream_name=data_stream_name)
File "plaso/engine/extractors.py", line 252, in ParseDataStream
parser_mediator, parser, file_entry, file_object=file_object)
File "plaso/engine/extractors.py", line 187, in _ParseFileEntryWithParser
parser.Parse(parser_mediator, file_object)
File "plaso/parsers/interface.py", line 269, in Parse
self.ParseFileObject(parser_mediator, file_object, **kwargs)
File "plaso/parsers/cups_ipp.py", line 240, in ParseFileObject
name, value = self.ReadPair(parser_mediator, file_object)
File "plaso/parsers/cups_ipp.py", line 329, in ReadPair
name = self.PAIR_NAME.parse_stream(file_object).text
File "/usr/lib/python2.7/site-packages/construct/core.py", line 198, in parse_stream
return self._parse(stream, Container())
File "/usr/lib/python2.7/site-packages/construct/core.py", line 670, in _parse
subobj = sc._parse(stream, context)
File "/usr/lib/python2.7/site-packages/construct/core.py", line 288, in _parse
return self._decode(self.subcon._parse(stream, context), context)
File "/usr/lib/python2.7/site-packages/construct/adapters.py", line 158, in _decode
obj = obj.decode(self.encoding)
File "/usr/lib64/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x98 in position 28: invalid start byte

# Fixed code
def ReadPair(self, parser_mediator, file_object):
    """Reads an attribute name and value pair from a CUPS IPP event.

    Args:
      parser_mediator: A parser mediator object (instance of ParserMediator).
      file_object: a file-like object that points to a file.

    Returns:
      A list of name and value. If name and value cannot be read both are
      set to None.
    """
    # Pair = Type ID + Name + Value.
    try:
        # Can be:
        #   Group ID + IDtag = Group ID (1byte) + Tag ID (1byte) + '0x00'.
        #   IDtag = Tag ID (1byte) + '0x00'.
        type_id = self.INTEGER_8.parse_stream(file_object)
        if type_id == self.GROUP_END:
            return None, None

        elif type_id in self.GROUP_LIST:
            # If it is a group ID we must read the next byte that contains
            # the first TagID.
            type_id = self.INTEGER_8.parse_stream(file_object)

        # 0x00 separator character.
        _ = self.INTEGER_8.parse_stream(file_object)

    except (IOError, construct.FieldError):
        logging.warning(
            "[{0:s}] Unsupported identifier in file: {1:s}.".format(
                self.NAME, parser_mediator.GetDisplayName()
            )
        )
        return None, None

    # Name = Length name + name + 0x00
    try:
        name = self.PAIR_NAME.parse_stream(file_object).text
    except (IOError, UnicodeDecodeError, construct.FieldError):
        logging.warning(
            "[{0:s}] Unsupported name in file: {1:s}.".format(
                self.NAME, parser_mediator.GetDisplayName()
            )
        )
        return None, None

    # Value: can be integer, boolean or text select by Type ID.
    try:
        if type_id in [
            self.TYPE_GENERAL_INTEGER,
            self.TYPE_INTEGER,
            self.TYPE_ENUMERATION,
        ]:
            value = self.INTEGER.parse_stream(file_object).integer

        elif type_id == self.TYPE_BOOL:
            value = bool(self.BOOLEAN.parse_stream(file_object).integer)

        elif type_id == self.TYPE_DATETIME:
            datetime = self.DATETIME.parse_stream(file_object)
            value = timelib.Timestamp.FromRFC2579Datetime(
                datetime.year,
                datetime.month,
                datetime.day,
                datetime.hour,
                datetime.minutes,
                datetime.seconds,
                datetime.deciseconds,
                datetime.direction_from_utc,
                datetime.hours_from_utc,
                datetime.minutes_from_utc,
            )

        else:
            value = self.TEXT.parse_stream(file_object)

    except (IOError, UnicodeDecodeError, construct.FieldError):
        logging.warning(
            "[{0:s}] Unsupported value in file: {1:s}.".format(
                self.NAME, parser_mediator.GetDisplayName()
            )
        )
        return None, None

    return name, value