Skip to content

Expose more detailed functions to File and FileRef - #1

Closed
buganini wants to merge 6 commits into
taglib:masterfrom
buganini:master
Closed

buganini wants to merge 6 commits into
taglib:masterfrom
buganini:master

Conversation

@buganini

@buganini buganini commented May 1, 2011

Copy link
Copy Markdown

Hi, I've forwarded/added some functions to File and FileRef,
in order to make my program buganini/bsdtagconv easier.

but I don't know much about doxygen, so I didn't add any comments.
and there are some duplicated functions due to case issue of function naming.

Regards,
Buganini

buganini added 6 commits May 1, 2011 22:34
    ID3v1::Tag * ID3v1Tag (bool create);
    ID3v2::Tag * ID3v2Tag (bool create);
    APE::Tag * APETag (bool create);
    Ogg::XiphComment * XiphComment (bool create);
    bool strip (int tags);

Add preferedType
    bool hasAPETag();
    bool hasASFTag();
    bool hasID3v1Tag();
    bool hasID3v2Tag();
    bool hasXiphComment();
    bool hasTag();
exception:
  ID3v2 in MPC always return NULL, I don't know how to implement it
  MPEG, TrueAudio, WavPack has already done it right.
@buganini

buganini commented May 1, 2011

Copy link
Copy Markdown
Author

BTW, the hasXXX() may be retired if XXXtag() return NULL properly.

@lalinsky

lalinsky commented May 2, 2011

Copy link
Copy Markdown
Member

Hi, I'm afraid this can't be merged into master. We maintain binary compatibility for all TagLib 1.x releases, which this patch breaks (you can't add virtual methods to a classs).

So, the only option would be TagLib 2.0, but I'm not sure this is particularly good idea. TagLib::File is meant to be a generic class. There will be almost always new formats in the future, which would also have to be added to the class, breaking binary compatibility again. I think a better solution would be to have abstract classes like this:

class ID3v1TagProvider {
public:
  ID3v1::Tag *ID3v1Tag() = 0;
};

class ID3v2TagProvider {
public:
  ID3v2::Tag *ID3v2Tag() = 0;
};

And then have MPEG::File defined like this:

class File : public TagLib::File, public ID3v1TagProvider, public ID3v2TagProvider
{
  ...
};

This gives you the ability to retrieve specific tags without depending on a specific file class:

ID3v2TagProvider *tp = dynamic_cast<ID3v2TagProvider *>(file);
if(fp) {
  ID3v2::Tag *tag = tp->ID3v2Tag();
  ...
}

@buganini

buganini commented May 3, 2011

Copy link
Copy Markdown
Author

Okay, thank you,
I'm new to C++, there are things to learn :-)

@buganini buganini closed this May 3, 2011
@HappenOoo HappenOoo mentioned this pull request Mar 16, 2018
ufleisch pushed a commit that referenced this pull request Aug 15, 2026
DSF::Properties::read computes

    d->length = d->samplingFrequency > 0
        ? static_cast<unsigned int>(static_cast<double>(d->sampleCount)
                                    * 1000.0 / d->samplingFrequency + 0.5)
        : 0;

sampleCount is a long long taken straight from the file and
samplingFrequency is an unsigned int from the file, so the millisecond
count can land well outside unsigned int. Converting a floating point
value the destination type cannot represent is undefined:

  taglib/dsf/dsfproperties.cpp:132:35: runtime error: 8.41595e+09 is
  outside the range of representable values of type 'unsigned int'
    #0 TagLib::DSF::Properties::read(TagLib::ByteVector const&)
    #1 TagLib::DSF::Properties::Properties(...)
    #10 TagLib::FileRef::FileRef(char const*, bool, ...)

A negative sampleCount converts just as badly, so guard that too.

Report an unknown length instead of converting, matching what a zero
sampling frequency already does. Nothing changes for a valid file:
tests/data/empty10ms.dsf reads lengthMs=10 bitrate=5645 rate=2822400
ch=2 both before and after.

Found by mutating the files in tests/data and running them through a
parse, read properties and save round trip under UBSan.

Assisted-By: Claude Code (Claude Opus 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants