<commit_before>from collections import OrderedDict


class BaseHandler:
    def __init__(self, file, file_name):
        self.file = file
        self.file_name = file_name
        self.info = OrderedDict()

    def read(self, offset, size):
        return self.file[offset:offset + size]<commit_msg>Add bounds checking to BaseHandler.read()<commit_after>from collections import OrderedDict


class BaseHandler:
    def __init__(self, file, file_name):
        self.file = file
        self.file_name = file_name
        self.info = OrderedDict()

    def read(self, offset, size):
        if offset < 0:
            raise IndexError("File offset must be greater than 0")

        if offset + size >= len(self.file):
            raise IndexError("Cannot read beyond the end of the file")

        return self.file[offset:offset + size]
{'fraction_non_alphanumeric': 0.08862275449101796, 'fraction_numerical': 0.0023952095808383233, 'mean_word_length': 2.765765765765766, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4116843', 'n_tokens_mistral': 237, 'n_tokens_neox': 228, 'n_words': 73}