1
1
/* flac - Command-line FLAC encoder/decoder
2
* Copyright (C) 2002,2003,2004,2005 Josh Coalson
2
* Copyright (C) 2002,2003,2004,2005,2006,2007 Josh Coalson
4
4
* This program is free software; you can redistribute it and/or
5
5
* modify it under the terms of the GNU General Public License
102
104
FLAC__StreamMetadata_VorbisComment_Entry entry;
104
FLAC__bool needs_free = false;
106
107
FLAC__ASSERT(0 != block);
107
108
FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
108
109
FLAC__ASSERT(0 != field);
109
110
FLAC__ASSERT(0 != needs_write);
112
entry.entry = (FLAC__byte *)field->field;
114
else if(utf8_encode(field->field, &converted) >= 0) {
115
entry.entry = (FLAC__byte *)converted;
119
*violation = "couldn't convert comment to UTF-8";
123
entry.length = strlen((const char *)entry.entry);
125
if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
112
if(field->field_value_from_file) {
113
/* read the file into 'data' */
116
const off_t size = grabbag__file_get_filesize(field->field_value);
118
*violation = "can't open file for tag value";
121
if(size >= 0x100000) { /* magic arbitrary limit, actual format limit is near 16MB */
122
*violation = "file for tag value is too large";
125
if(0 == (data = malloc(size+1)))
126
die("out of memory allocating tag value");
128
if(0 == (f = fopen(field->field_value, "rb")) || fread(data, 1, size, f) != (size_t)size) {
132
*violation = "error while reading file for tag value";
136
if(strlen(data) != (size_t)size) {
138
*violation = "file for tag value has embedded NULs";
142
/* move 'data' into 'converted', converting to UTF-8 if necessary */
146
else if(utf8_encode(data, &converted) >= 0) {
151
*violation = "error converting file contents to UTF-8 for tag value";
155
/* create and entry and append it */
156
if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, field->field_name, converted)) {
128
*violation = "memory allocation failure";
158
*violation = "file for tag value is not valid UTF-8";
162
if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
163
*violation = "memory allocation failure";
171
FLAC__bool needs_free = false;
173
entry.entry = (FLAC__byte *)field->field;
175
else if(utf8_encode(field->field, &converted) >= 0) {
176
entry.entry = (FLAC__byte *)converted;
180
*violation = "error converting comment to UTF-8";
183
entry.length = strlen((const char *)entry.entry);
184
if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) {
188
* our previous parsing has already established that the field
189
* name is OK, so it must be the field value
191
*violation = "tag value for is not valid UTF-8";
195
if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
198
*violation = "memory allocation failure";
132
202
*needs_write = true;