# Buggy code
def WriteEntry(self, data):
    """Writes an entry to the file-like object.

    Args:
      data (bytes): data.

    Returns:
      int: offset of the entry within the temporary file.

    Raises:
      IOError: if the serialized data stream was not opened for writing or
          the entry cannot be written to the serialized data stream.
    """
    if not self._file_object:
        raise IOError("Unable to write to closed serialized data stream.")

    data_size = len(data)
    data_end_offset = self._file_object.tell() + self._DATA_ENTRY_SIZE + data_size
    if data_end_offset > self._maximum_data_size:
        raise IOError("Unable to write data entry size value out of bounds.")

    data_size = construct.ULInt32("size").build(data_size)
    self._file_object.write(data_size)
    self._file_object.write(data)

    return self._file_object.tell()


# Traceback (IOError)
Traceback (most recent call last):
File "/usr/local/bin/log2timeline.py", line 4, in <module>
__import__('pkg_resources').run_script('plaso==1.5.2.post20170123', 'log2timeline.py')
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 739, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1494, in run_script
exec(code, namespace, namespace)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/EGG-INFO/scripts/log2timeline.py", line 678, in <module>
if not Main():
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/EGG-INFO/scripts/log2timeline.py", line 664, in Main
tool.ProcessSources()
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/EGG-INFO/scripts/log2timeline.py", line 575, in ProcessSources
worker_memory_limit=self._worker_memory_limit)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/frontend/extraction_frontend.py", line 391, in ProcessSources
worker_memory_limit=worker_memory_limit)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/multi_processing/task_engine.py", line 770, in ProcessSources
filter_find_specs=filter_find_specs)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/multi_processing/task_engine.py", line 275, in _ProcessSources
self._ScheduleTasks(storage_writer)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/multi_processing/task_engine.py", line 407, in _ScheduleTasks
self._MergeTaskStorage(storage_writer)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/multi_processing/task_engine.py", line 205, in _MergeTaskStorage
maximum_number_of_containers=self._MAXIMUM_NUMBER_OF_CONTAINERS)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/storage/gzip_file.py", line 415, in MergeAttributeContainers
self._AddAttributeContainer(attribute_container)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/storage/gzip_file.py", line 348, in _AddAttributeContainer
self._storage_writer.AddEvent(attribute_container)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/storage/zip_file.py", line 3050, in AddEvent
self._storage_file.AddEvent(event)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/storage/zip_file.py", line 2346, in AddEvent
self._WriteSerializedEvents()
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/storage/zip_file.py", line 2021, in _WriteSerializedEvents
self._serialized_events_heap, self._event_stream_number)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/storage/zip_file.py", line 2055, in _WriteSerializedEventsHeap
entry_data_offset = data_stream.WriteEntry(entry_data)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170123-py2.7.egg/plaso/storage/zip_file.py", line 565, in WriteEntry
raise IOError(u'Unable to write data entry size value out of bounds.')
IOError: Unable to write data entry size value out of bounds.
2017-01-24 04:33:12,385 [WARNING] (MainProcess) PID:3458 <zeromq_queue> main_task_queue timeout waiting for a request.
2017-01-24 04:33:21,953 [WARNING] (MainProcess) PID:3458 <zeromq_queue> main_task_queue timeout waiting for a request.
2017-01-24 04:33:31,410 [WARNING] (MainProcess) PID:3458 <zeromq_queue> main_task_queue timeout waiting for a request.
2017-01-24 04:33:41,243 [WARNING] (MainProcess) PID:3458 <zeromq_queue> main_task_queue timeout waiting for a request.
2017-01-24 04:33:51,040 [WARNING] (MainProcess) PID:3458 <zeromq_queue> main_task_queue timeout waiting for a request.

# Fixed code
def WriteEntry(self, data):
    """Writes an entry to the file-like object.

    Args:
      data (bytes): data.

    Returns:
      int: offset of the entry within the temporary file.

    Raises:
      IOError: if the serialized data stream was not opened for writing or
          the entry cannot be written to the serialized data stream.
    """
    if not self._file_object:
        raise IOError("Unable to write to closed serialized data stream.")

    data_size = len(data)
    # TODO: Fix maximum size limit handling to create new stream.
    # data_end_offset = (
    #    self._file_object.tell() + self._DATA_ENTRY_SIZE + data_size)
    # if data_end_offset > self._maximum_data_size:
    #  raise IOError(u'Unable to write data entry size value out of bounds.')

    data_size = construct.ULInt32("size").build(data_size)
    self._file_object.write(data_size)
    self._file_object.write(data)

    return self._file_object.tell()