Git Product home page Git Product logo

Comments (5)

maugre avatar maugre commented on May 22, 2024 1

Seeing how it's done in the matcher functions with matching against only the 2 bytes, I've changed mine to this:

Mp3(buf []byte) bool {
return len(buf) > 2 &&
((buf[0] == 0x49 && buf[1] == 0x44 && buf[2] == 0x33) ||
(buf[0] == 0xFF && buf[1] == 0xfa) ||
(buf[0] == 0xFF && buf[1] == 0xfb))
}

The line with 0xfa is added with no other changes. That now works for me on the files that were previously failing.

Thanks!

from filetype.

h2non avatar h2non commented on May 22, 2024

Thanks for reporting this. What you mention makes absolute sense. The prefered way is using or logical operator.

from filetype.

maugre avatar maugre commented on May 22, 2024

There may be more possibilities for that second byte. See spec here: http://www.mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm

Edit: I've been looking into this further. We only want MPEG-1 Layer III for MP3 audio, which leaves 0xFA and 0xFB depending on whether the 'protection' bit is set, so this is sufficient. Layer II would be MP2 files so another test.

from filetype.

maugre avatar maugre commented on May 22, 2024

I modified my local matcher function in this way to check the first bit only once:

func Mp3(buf []byte) bool {
return len(buf) > 2 &&
((buf[0] == 0x49 && buf[1] == 0x44 && buf[2] == 0x33) || // ID3v2
// Final bit (has crc32) may be or may not be set.
(buf[0] == 0xFF && (buf[1] == 0xFA || buf[1] == 0xFB)))
}

Would that be preferable?

from filetype.

h2non avatar h2non commented on May 22, 2024

I would suggest the same. One check is perfect.

from filetype.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.