saurabhshri / simple-yet-powerful-srt-subtitle-parser-cpp

A single header simple, powerful and full blown srt subtitle parser written in C++.
Other
51 stars 15 forks source link

Expression: vector subscript out of range #17

Open TheEeveeLovers opened 7 months ago

TheEeveeLovers commented 7 months ago

When I try to load captions, the parser doesn't even start because of the following error: image Call Stack:

>   SRTSynchedLyrics.exe!std::vector<std::string,std::allocator<std::string>>::operator[](const unsigned __int64 _Pos) Line 1948    C++
    SRTSynchedLyrics.exe!SubtitleItem::timeMSec(std::string value) Line 313 C++
    SRTSynchedLyrics.exe!SubtitleItem::SubtitleItem(int subNo, std::string startTime, std::string endTime, std::string text, bool ignore, std::string justDialogue, int speakerCount, int nonDialogueCount, int styleTagCount, int wordCount, std::vector<std::string,std::allocator<std::string>> speaker, std::vector<std::string,std::allocator<std::string>> nonDialogue, std::vector<std::string,std::allocator<std::string>> styleTags, std::vector<std::string,std::allocator<std::string>> word) Line 286   C++
    SRTSynchedLyrics.exe!SubRipParser::parse(std::string fileName) Line 248 C++
    SRTSynchedLyrics.exe!SubRipParser::SubRipParser(std::string fileName) Line 262  C++
    SRTSynchedLyrics.exe!SubtitleParserFactory::getParser() Line 155    C++
    SRTSynchedLyrics.exe!LoadCaptions(std::string filePath) Line 35 C++
    SRTSynchedLyrics.exe!startup() Line 212 C++
    SRTSynchedLyrics.exe!SDL_main(int argc, char * * args) Line 223 C++
    SRTSynchedLyrics.exe!main_getcmdline() Line 82  C
    [External Code] 

Code:

void LoadCaptions(std::string filePath) {
    SubtitleParserFactory* subParserFactory = new SubtitleParserFactory(filePath);
    SubtitleParser* parser = subParserFactory->getParser(); // Error suspect
    // More code that doesn't get run due to error
}

LoadCaptions("12 All Apologies 1.srt");

SRT File: (zipped so it can upload to GitHub) 12 All Apologies 1.zip For reference, this file works completely fine in VLC.

TheEeveeLovers commented 7 months ago

I added a new line character at the beginning of the SRT file and got the same error, not before getting another Run-Time Check Failure #3 - The variable 'subNo' is being used without being initialized. -- srtparser.h, line 248

Call Stack:

>   SRTSynchedLyrics.exe!SubRipParser::parse(std::string fileName) Line 248 C++
    SRTSynchedLyrics.exe!SubRipParser::SubRipParser(std::string fileName) Line 262  C++
    SRTSynchedLyrics.exe!SubtitleParserFactory::getParser() Line 155    C++
    SRTSynchedLyrics.exe!LoadCaptions(std::string filePath) Line 34 C++
    SRTSynchedLyrics.exe!startup() Line 212 C++
    SRTSynchedLyrics.exe!SDL_main(int argc, char * * args) Line 223 C++
    SRTSynchedLyrics.exe!main_getcmdline() Line 82  C
    [External Code] 

Seems like part of an entirely different bug? Because here, it seems that the new line character (nothing) is being read as the caption index.

TheEeveeLovers commented 7 months ago

I just tried opening the example SRT, and it worked fine What's wrong with my file?

TheEeveeLovers commented 7 months ago

Apparently there's too many captions Limit is 47

TheEeveeLovers commented 7 months ago

OK, found the problem There was an additional space before the arrow on the 48th entry