Skip to content

APEv2 "has footer" bit inconsistency #1083

Open

Description

@hyperquantum

While looking at the implementation of APEv2 tag parsing/rendering I found an inconsistency between the implementation and the documentation of the tag format. It's about the "has footer" bit of the flags in the header/footer.

The implementation in apefooter.cpp sets the "has footer" bit to zero to indicate that the footer is present:

flags[30] = false; // footer is always present

The parsing of the tag is consistent with this:

d->footerPresent = !flags[30];

The documentation however states that a zero bit means that the footer is absent, in ape-tag-format.txt:

|-----------------|-------------|---------------------------------|
| Contains Footer | Bit 30      | 1 - has footer | 0 - no footer  |
|-----------------|-------------|---------------------------------|

I assume that the implementation is correct and the documentation is wrong, because a problem with the implementation would have already been noticed.

The Hydrogenaudio documentation (https://wiki.hydrogenaud.io/index.php?title=Ape_Tags_Flags) also states that a zero bit means absence of the footer. But the documentation at https://mutagen-specs.readthedocs.io/en/latest/apev2/apev2.html states that a zero bit means that the footer is present, as it is currently implemented by taglib:

Bit 30
        0: Tag contains a footer
        1: Tag contains no footer

So am I correct in assuming that the taglib and Hydrogenaudio documentation both need to be fixed?

Activity

  1. sbooth commented on Mar 5, 2023

    @sbooth
    Contributor

    APETag.h in the Monkey's Audio SDK contains the following code:

    /**************************************************************************************************
    APETag layout
    
    1) Header - APE_TAG_FOOTER (optional) (32 bytes)
    2) Fields (array):
            Value Size (4 bytes)
            Flags (4 bytes)
            Field Name (? ANSI bytes -- requires NULL terminator -- in range of 0x20 (space) to 0x7E (tilde))
            Value ([Value Size] bytes)
    3) Footer - APE_TAG_FOOTER (32 bytes)
    **************************************************************************************************/
    
    /**************************************************************************************************
    Footer (and header) flags
    **************************************************************************************************/
    #define APE_TAG_FLAG_CONTAINS_FOOTER            (1 << 30)
    
    /**************************************************************************************************
    The footer at the end of APE tagged files (can also optionally be at the front of the tag)
    **************************************************************************************************/
    class APE_TAG_FOOTER
    {
    protected:
        char m_cID[8];              // should equal 'APETAGEX'
        int m_nVersion;             // equals CURRENT_APE_TAG_VERSION
        int m_nSize;                // the complete size of the tag, including this footer (excludes header)
        int m_nFields;              // the number of fields in the tag
        int m_nFlags;               // the tag flags
        char m_cReserved[8];        // reserved for later use (must be zero)
    };

    So at first glance it does appear that a zero bit should mean the absence of a footer.

  2. ufleisch commented on Mar 6, 2023

    @ufleisch
    Contributor

    After having a look at APE and MPC tags generated by various applications (e.g. deadbeef, JRiver Media Center, Media Monkey, Mp3Tag, TagScan), I only found one file (from JRiver Media Center) which had the bit 30 set. From the other applications, there were tags having only a footer (with all flags zero 00000000) and tags with header (flags 000000a0) and footer (flags 00000080). Applications using TagLib also write header and footer. Therefore according to this observations, I would say that bit 30 = 0 means "has footer" (i.e. the implementation is correct and the documentation is wrong).

    Having a zero bit for "footer present" does not seem logical, but an explanation could be that in the old APE Tags 1.0 format all flags are zero (according to Hydrogenaudio), so this would keep the footer compatible (and the footer seems to be the thing which should be always present if the tag is at the end of the file).

  3. sbooth commented on Mar 7, 2023

    @sbooth
    Contributor

    I compressed a WAVE file using Monkey's Audio SDK 9.04 and the flags were 0x40000000. In absence of a specification I'd be inclined to say that the official SDK is normative, but it's odd that implementations would vary.

  4. hyperquantum commented on Mar 7, 2023

    @hyperquantum
    ContributorAuthor

    After giving it some thought I found a perfectly logical explanation: the implementations never actually use the value of the "has footer" bit for anything. In most cases (all?) the APE tag is at the end of the file, which means that the footer is mandatory, and implementations look for the footer first to determine if the APE tag is present. Identification of the footer is done by looking for the magic string "APETAGEX" at some fixed offset (end of the file minus 32 bytes or something similar). Once you know where the footer is, there is no need to look at the "has footer" bit.

    I am not sure what should be done. Anyone creating their own implementation should probably be warned that the value of the bit is unreliable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions