def clean_offsetscounts(offsets, counts):
    """Return cleaned offsets and byte counts.

    Remove zero offsets and counts.
    Use to sanitize StripOffsets and StripByteCounts tag values.

    """
    # TODO: cythonize this
    offsets = list(offsets)
    counts = list(counts)
    size = len(offsets)
    if size != len(counts):
        raise ValueError('StripOffsets and StripByteCounts mismatch')
    j = 0
    for i, (o, b) in enumerate(zip(offsets, counts)):
        if b > 0:
            if o > 0:
                if i > j:
                    offsets[j] = o
                    counts[j] = b
                j += 1
                continue
            raise ValueError('invalid offset')
        log.warning('clean_offsetscounts: empty bytecount')
    if size == len(offsets):
        return offsets, counts
    if j == 0:
        return [offsets[0]], [counts[0]]
    return offsets[:j], counts[:j]