diff --git a/src/modules/frames/apic_frame.c b/src/modules/frames/apic_frame.c index ba1d9cd..94747d7 100644 --- a/src/modules/frames/apic_frame.c +++ b/src/modules/frames/apic_frame.c @@ -51,18 +51,18 @@ ID3v2_ApicFrame* ApicFrame_parse(CharStream* frame_cs, const int id3_major_versi CharStream_seek(frame_cs, ID3v2_FRAME_ENCODING_LENGTH, SEEK_CUR); // skip encoding const int mime_type_size = ID3v2_strlent(CharStream_get_cur(frame_cs)); - char mime_type[mime_type_size]; + char* mime_type = malloc(mime_type_size * sizeof(char)); CharStream_read(frame_cs, mime_type, mime_type_size); const char picture_type = CharStream_getc(frame_cs); const int description_size = ID3v2_strlent(CharStream_get_cur(frame_cs)); - char description[description_size]; + char* description = malloc(description_size * sizeof(char)); CharStream_read(frame_cs, description, description_size); const int pic_size = header->size - ID3v2_FRAME_ENCODING_LENGTH - mime_type_size - ID3v2_APIC_FRAME_PICTURE_TYPE_LENGTH - description_size; - char pic_data[pic_size]; + char* pic_data = malloc(pic_size * sizeof(char)); CharStream_read(frame_cs, pic_data, pic_size); ID3v2_ApicFrame* frame = @@ -70,6 +70,9 @@ ID3v2_ApicFrame* ApicFrame_parse(CharStream* frame_cs, const int id3_major_versi FrameHeader_free(header); // we only needed the header to parse the data + free(mime_type); + free(description); + free(pic_data); return frame; } diff --git a/src/modules/frames/comment_frame.c b/src/modules/frames/comment_frame.c index 947f72d..df55562 100644 --- a/src/modules/frames/comment_frame.c +++ b/src/modules/frames/comment_frame.c @@ -49,17 +49,19 @@ ID3v2_CommentFrame* CommentFrame_parse(CharStream* frame_cs, const int id3_major CharStream_read(frame_cs, lang, ID3v2_COMMENT_FRAME_LANGUAGE_LENGTH); const int short_desc_size = ID3v2_strlent(CharStream_get_cur(frame_cs)); - char short_desc[short_desc_size]; + char* short_desc = malloc(short_desc_size * sizeof (char)); CharStream_read(frame_cs, short_desc, short_desc_size); const int comment_size = ID3v2_strlent(CharStream_get_cur(frame_cs)); - char comment[comment_size]; + char* comment = malloc(comment_size * sizeof(char)); CharStream_read(frame_cs, comment, comment_size); ID3v2_CommentFrame* frame = CommentFrame_new(header->flags, lang, short_desc, comment); FrameHeader_free(header); // we only needed the header to parse the data + free(comment); + free(short_desc); return frame; } diff --git a/src/modules/frames/text_frame.c b/src/modules/frames/text_frame.c index 54cec80..4bd3448 100644 --- a/src/modules/frames/text_frame.c +++ b/src/modules/frames/text_frame.c @@ -37,13 +37,19 @@ ID3v2_TextFrame* TextFrame_parse(CharStream* frame_cs, const int id3_major_versi CharStream_seek(frame_cs, ID3v2_FRAME_ENCODING_LENGTH, SEEK_CUR); // skip encoding const int text_size = header->size - ID3v2_FRAME_ENCODING_LENGTH; - char text[text_size]; + const size_t string_termination_bytes = 2; + char* text = malloc((string_termination_bytes + text_size) * sizeof(char)); CharStream_read(frame_cs, text, text_size); + // Adding string termination bytes in case the stored string doesn't have those + for (int i = 0; i < string_termination_bytes; ++i) + text[text_size + i] = 0x00; + ID3v2_TextFrame* frame = TextFrame_new(header->id, header->flags, text); FrameHeader_free(header); // we only needed the header to parse the data + free(text); return frame; }