You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
APETag.h in the Monkey's Audio SDK contains the following code:
/**************************************************************************************************APETag layout1) 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**************************************************************************************************/
#defineAPE_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)**************************************************************************************************/classAPE_TAG_FOOTER
{
protected:char m_cID[8]; // should equal 'APETAGEX'int m_nVersion; // equals CURRENT_APE_TAG_VERSIONint m_nSize; // the complete size of the tag, including this footer (excludes header)int m_nFields; // the number of fields in the tagint m_nFlags; // the tag flagschar 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.
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).
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.
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.
Activity
sbooth commentedon Mar 5, 2023
APETag.hin the Monkey's Audio SDK contains the following code:So at first glance it does appear that a zero bit should mean the absence of a footer.
ufleisch commentedon Mar 6, 2023
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).
sbooth commentedon Mar 7, 2023
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.
hyperquantum commentedon Mar 7, 2023
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.