~ubuntu-branches/ubuntu/utopic/flac/utopic-security

« back to all changes in this revision

Viewing changes to src/test_libFLAC++/metadata_manip.cpp

  • Committer: Package Import Robot
  • Author(s): Fabian Greffrath
  • Date: 2013-06-07 10:24:30 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20130607102430-x7e7zt462c0tuetp
Tags: 1.3.0-1
* Imported Upstream version 1.3.0 (Closes: #527542, #705601).
* Update debian/watch file, thanks Ulrich Klauer (Closes: #710062).
* Revert "Remove manpages from master branch."
* Imported Upstream version 1.3.0
* Convert package to "3.0 (quilt)" source format.
* Remove all patches, they have either been merged upstream or do not
  apply anymore (tested).
* Explicitly enable static libraries.
* Simplify debian/libflac-doc.install.
* Bump shlibs for added symbols.
* Remove needless Build-Depends: libid3-3.8.3-dev.
* Update Homepage field.
* Repair upstream manpage regeneration rule.
* Bump Build-Depends: debhelper (>= 9).
* Fix vcs-field-not-canonical.
* Import two patches from upstream GIT:
  + Add missing config.h includes.
  + Fix local_strcat() to terminate string correctly.
* Disable 3DNow! optimizations, enable SSE only on amd64, enable Altivec
  only on ppc64, disable ASM optimizations elsewhere.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* test_libFLAC++ - Unit tester for libFLAC++
2
 
 * Copyright (C) 2002,2003,2004,2005,2006,2007  Josh Coalson
 
2
 * Copyright (C) 2002-2009  Josh Coalson
 
3
 * Copyright (C) 2011-2013  Xiph.Org Foundation
3
4
 *
4
5
 * This program is free software; you can redistribute it and/or
5
6
 * modify it under the terms of the GNU General Public License
11
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
13
 * GNU General Public License for more details.
13
14
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
 */
18
19
 
19
20
#if HAVE_CONFIG_H
23
24
#include <stdio.h>
24
25
#include <stdlib.h> /* for malloc() */
25
26
#include <string.h> /* for memcpy()/memset() */
26
 
#if defined _MSC_VER || defined __MINGW32__
27
 
#include <sys/utime.h> /* for utime() */
28
 
#include <io.h> /* for chmod() */
29
 
#if _MSC_VER <= 1600 /* @@@ [2G limit] */
30
 
#define fseeko fseek
31
 
#define ftello ftell
32
 
#endif
33
 
#else
34
27
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
 
28
#ifdef _MSC_VER
 
29
#include <sys/utime.h>
 
30
#else
35
31
#include <utime.h> /* for utime() */
 
32
#endif
 
33
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
36
34
#include <unistd.h> /* for chown(), unlink() */
37
35
#endif
38
36
#include <sys/stat.h> /* for stat(), maybe chmod() */
40
38
#include "FLAC++/decoder.h"
41
39
#include "FLAC++/metadata.h"
42
40
#include "share/grabbag.h"
 
41
#include "share/compat.h"
 
42
#include "share/macros.h"
 
43
#include "share/safe_str.h"
43
44
extern "C" {
44
45
#include "test_libs_common/file_utils_flac.h"
45
46
}
189
190
        }
190
191
}
191
192
 
192
 
void add_to_padding_length_(unsigned index, int delta)
 
193
void add_to_padding_length_(unsigned indx, int delta)
193
194
{
194
 
        FLAC::Metadata::Padding *padding = dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[index]);
 
195
        FLAC::Metadata::Padding *padding = dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[indx]);
195
196
        FLAC__ASSERT(0 != padding);
196
197
        padding->set_length((unsigned)((int)padding->get_length() + delta));
197
198
}
203
204
bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
204
205
{
205
206
        static const char *tempfile_suffix = ".metadata_edit";
 
207
        size_t destlen = strlen(filename) + strlen(tempfile_suffix) + 1;
206
208
 
207
 
        if(0 == (*tempfilename = (char*)malloc(strlen(filename) + strlen(tempfile_suffix) + 1)))
 
209
        if(0 == (*tempfilename = (char*)malloc(destlen)))
208
210
                return false;
209
 
        strcpy(*tempfilename, filename);
210
 
        strcat(*tempfilename, tempfile_suffix);
 
211
        flac_snprintf(*tempfilename, destlen, "%s%s", filename, tempfile_suffix);
211
212
 
212
 
        if(0 == (*tempfile = fopen(*tempfilename, "wb")))
 
213
        if(0 == (*tempfile = flac_fopen(*tempfilename, "wb")))
213
214
                return false;
214
215
 
215
216
        return true;
223
224
        }
224
225
 
225
226
        if(0 != *tempfilename) {
226
 
                (void)unlink(*tempfilename);
 
227
                (void)flac_unlink(*tempfilename);
227
228
                free(*tempfilename);
228
229
                *tempfilename = 0;
229
230
        }
242
243
        }
243
244
 
244
245
#if defined _MSC_VER || defined __MINGW32__ || defined __EMX__
245
 
        /* on some flavors of windows, rename() will fail if the destination already exists */
246
 
        if(unlink(filename) < 0) {
 
246
        /* on some flavors of windows, flac_rename() will fail if the destination already exists */
 
247
        if(flac_unlink(filename) < 0) {
247
248
                cleanup_tempfile_(tempfile, tempfilename);
248
249
                return false;
249
250
        }
250
251
#endif
251
252
 
252
 
        if(0 != rename(*tempfilename, filename)) {
 
253
        if(0 != flac_rename(*tempfilename, filename)) {
253
254
                cleanup_tempfile_(tempfile, tempfilename);
254
255
                return false;
255
256
        }
259
260
        return true;
260
261
}
261
262
 
262
 
bool get_file_stats_(const char *filename, struct stat *stats)
 
263
bool get_file_stats_(const char *filename, struct flac_stat_s *stats)
263
264
{
264
265
        FLAC__ASSERT(0 != filename);
265
266
        FLAC__ASSERT(0 != stats);
266
 
        return (0 == stat(filename, stats));
 
267
        return (0 == flac_stat(filename, stats));
267
268
}
268
269
 
269
 
void set_file_stats_(const char *filename, struct stat *stats)
 
270
void set_file_stats_(const char *filename, struct flac_stat_s *stats)
270
271
{
271
272
        struct utimbuf srctime;
272
273
 
275
276
 
276
277
        srctime.actime = stats->st_atime;
277
278
        srctime.modtime = stats->st_mtime;
278
 
        (void)chmod(filename, stats->st_mode);
279
 
        (void)utime(filename, &srctime);
 
279
        (void)flac_chmod(filename, stats->st_mode);
 
280
        (void)flac_utime(filename, &srctime);
280
281
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
281
 
        (void)chown(filename, stats->st_uid, (gid_t)(-1));
282
 
        (void)chown(filename, (uid_t)(-1), stats->st_gid);
 
282
        FLAC_CHECK_RETURN(chown(filename, stats->st_uid, (gid_t)(-1)));
 
283
        FLAC_CHECK_RETURN(chown(filename, (uid_t)(-1), stats->st_gid));
283
284
#endif
284
285
}
285
286
 
296
297
 
297
298
static int chain_seek_cb_(::FLAC__IOHandle handle, FLAC__int64 offset, int whence)
298
299
{
299
 
        off_t o = (off_t)offset;
 
300
        FLAC__off_t o = (FLAC__off_t)offset;
300
301
        FLAC__ASSERT(offset == o);
301
302
        return fseeko((FILE*)handle, o, whence);
302
303
}
329
330
                callbacks.eof = chain_eof_cb_;
330
331
 
331
332
                if(chain.check_if_tempfile_needed(use_padding)) {
332
 
                        struct stat stats;
 
333
                        struct flac_stat_s stats;
333
334
                        FILE *file, *tempfile;
334
335
                        char *tempfilename;
335
336
                        if(preserve_file_stats) {
336
337
                                if(!get_file_stats_(filename, &stats))
337
338
                                        return false;
338
339
                        }
339
 
                        if(0 == (file = fopen(filename, "rb")))
 
340
                        if(0 == (file = flac_fopen(filename, "rb")))
340
341
                                return false; /*@@@@ chain status still says OK though */
341
342
                        if(!open_tempfile_(filename, &tempfile, &tempfilename)) {
342
343
                                fclose(file);
357
358
                                set_file_stats_(filename, &stats);
358
359
                }
359
360
                else {
360
 
                        FILE *file = fopen(filename, "r+b");
 
361
                        FILE *file = flac_fopen(filename, "r+b");
361
362
                        if(0 == file)
362
363
                                return false; /*@@@@ chain status still says OK though */
363
 
                        if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks))
 
364
                        if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks)) {
 
365
                                fclose(file);
364
366
                                return false;
 
367
                        }
365
368
                        fclose(file);
366
369
                }
367
370
        }
383
386
 
384
387
                {
385
388
                        bool ret;
386
 
                        FILE *file = fopen(filename, "rb");
 
389
                        FILE *file = flac_fopen(filename, "rb");
387
390
                        if(0 == file)
388
391
                                return false; /*@@@@ chain status still says OK though */
389
392
                        ret = chain.read((::FLAC__IOHandle)file, callbacks, is_ogg);
532
535
                if (0 == (cuesheet = ::FLAC__metadata_object_new(::FLAC__METADATA_TYPE_CUESHEET)))
533
536
                        return die_("priming our metadata");
534
537
                cuesheet->is_last = false;
535
 
                strcpy(cuesheet->data.cue_sheet.media_catalog_number, "bogo-MCN");
 
538
                safe_strncpy(cuesheet->data.cue_sheet.media_catalog_number, "bogo-MCN", sizeof(cuesheet->data.cue_sheet.media_catalog_number));
536
539
                cuesheet->data.cue_sheet.lead_in = 123;
537
540
                cuesheet->data.cue_sheet.is_cd = false;
538
541
                if (!FLAC__metadata_object_cuesheet_insert_blank_track(cuesheet, 0))
2076
2079
 
2077
2080
        printf("read chain (callback-based)\n");
2078
2081
        {
2079
 
                FILE *file = fopen(flacfilename(is_ogg), "rb");
 
2082
                FILE *file = flac_fopen(flacfilename(is_ogg), "rb");
2080
2083
                if(0 == file)
2081
2084
                        return die_("opening file");
2082
2085
                if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
2097
2100
 
2098
2101
        printf("read chain (callback-based)\n");
2099
2102
        {
2100
 
                FILE *file = fopen(flacfilename(is_ogg), "rb");
 
2103
                FILE *file = flac_fopen(flacfilename(is_ogg), "rb");
2101
2104
                if(0 == file)
2102
2105
                        return die_("opening file");
2103
2106
                if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
2125
2128
 
2126
2129
        printf("read chain (callback-based)\n");
2127
2130
        {
2128
 
                FILE *file = fopen(flacfilename(is_ogg), "rb");
 
2131
                FILE *file = flac_fopen(flacfilename(is_ogg), "rb");
2129
2132
                if(0 == file)
2130
2133
                        return die_("opening file");
2131
2134
                if(!chain.read((::FLAC__IOHandle)file, callbacks)) {