<commit_before><?php
namespace brokencube\ID3;

class Reader
{
    /*
        http://id3.org/id3v2.3.0
    */
    
    protected $filename;
    protected $fp;
    protected $data;
    public function __construct($filename)
    {
        $this->filename = $filename;
    }

    protected function unpackSyncSafeInteger($bytes)
    {
        list(,$size) = unpack('N', $bytes);

        return ($size & 0x0000007F)
            + (($size & 0x00007F00) >> 1)
            + (($size & 0x007F0000) >> 2)
            + (($size & 0x7F000000) >> 3);
    }

    public function view()
    {
        $this->fp = fopen($this->filename,'r');
        
        $mainHeader = fread($this->fp, 10);
        // Check we have the expected magic string
        if (substr($mainHeader,0,3) != 'ID3') {
            return [];
        }
        
        $mainHeaderLength = $this->unpackSyncSafeInteger(substr($mainHeader, 6, 4));
        
        // Sanity check - if the decoded length value is larger than the file, we must be looking at junk data, bail out.
        if ($mainHeaderLength > filesize($this->filename)) {<commit_msg>Bailout of Empty ID3 headers<commit_after><?php
namespace brokencube\ID3;

class Reader
{
    /*
        http://id3.org/id3v2.3.0
    */
    
    protected $filename;
    protected $fp;
    protected $data;
    public function __construct($filename)
    {
        $this->filename = $filename;
    }

    protected function unpackSyncSafeInteger($bytes)
    {
        list(,$size) = unpack('N', $bytes);

        return ($size & 0x0000007F)
            + (($size & 0x00007F00) >> 1)
            + (($size & 0x007F0000) >> 2)
            + (($size & 0x7F000000) >> 3);
    }

    public function view()
    {
        $this->fp = fopen($this->filename,'r');
        
        $mainHeader = fread($this->fp, 10);
        // Check we have the expected magic string
        if (substr($mainHeader,0,3) != 'ID3') {
            return [];
        }
        
        $mainHeaderLength = $this->unpackSyncSafeInteger(substr($mainHeader, 6, 4));
        
        // Sanity check - if the decoded length value is larger than the file, we must be looking at junk data, bail out.
        if ($mainHeaderLength > filesize($this->filename)) {
            return [];
        }

        if ($mainHeaderLength < 10) {
{'fraction_non_alphanumeric': 0.1400086692674469, 'fraction_numerical': 0.04291287386215865, 'mean_word_length': 1.9819121447028423, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 29, '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': '3165617', 'n_tokens_mistral': 780, 'n_tokens_neox': 703, 'n_words': 172}