1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
diff -aruN quelcom-0.4.0.orig/bin/qwavheaderdump.cc quelcom-0.4.0/bin/qwavheaderdump.cc
--- quelcom-0.4.0.orig/bin/qwavheaderdump.cc 2005-10-09 03:24:10.000000000 -0700
+++ quelcom-0.4.0/bin/qwavheaderdump.cc 2005-10-09 03:24:33.000000000 -0700
@@ -1,7 +1,10 @@
# include <getopt.h> // getopt
# include <sys/types.h> // u_int16_t, u_int32_t
+# include <stdint.h> // uintptr_t, ISO C99 types
# include "qfile.hh"
+# include "qwavheader.hh"
# include "qexception.hh"
+# include "endian.hh"
/* caved in and used C's printf in a few places that don't seem to
* be expressible with ios
@@ -35,7 +38,7 @@
char data[4];
u_int32_t datalength;
-};
+} __attribute__((packed));
const unsigned int HEADERSIZE = sizeof(struct header);
@@ -126,6 +129,17 @@
continue;
}
+ if ((uintptr_t)f.getMap() % sizeof(u_int32_t) != 0) {
+ // should never happen with a mapping at offset 0, but if it does,
+ // we need to catch it rather than tossing subtle memory misread
+ // bugs. 32-bit alignment is adequate since no integer in a WAV header
+ // is longer
+ cerr << APPNAME << _(": mapping of header in '") << f.getName()
+ << _("' is not 32-bit aligned\n");
+ optind++;
+ continue;
+ }
+
struct header *header = (struct header*) f.getMap();
cout << f.getName() << " (" << f.getSize() << " bytes):" << endl;
@@ -143,12 +157,12 @@
}
}
- printf(_("\triff length: %d\n"),header->rifflength);
- if (header->rifflength!=f.getSize()-8) {
+ printf(_("\triff length: %d\n"),letohl(header->rifflength));
+ if (letohl(header->rifflength)!=f.getSize()-8) {
if (!quiet)
fprintf(stderr,_("\t\triff length field should be %d\n"),f.getSize()-8);
if (fix) {
- header->rifflength = f.getSize()-8;
+ header->rifflength = htolel(f.getSize()-8);
if (!quiet)
cerr << _("\t\tfixed\n");
}
@@ -176,30 +190,31 @@
}
}
- printf(_("\tfmt length: %d\n"),header->fmtlength);
- if (header->fmtlength!=16) {
+ printf(_("\tfmt length: %d\n"),letohl(header->fmtlength));
+ if (letohl(header->fmtlength)!=16) {
if (!quiet)
fprintf(stderr,_("\t\tfmt length field should be %d\n"),16);
if (fix) {
- header->fmtlength = 16;
+ header->fmtlength = htolel(16);
if (!quiet)
cerr << _("\t\tfixed\n");
}
}
- printf("\tformat: %d\n",header->format);
- if (header->format!=1) {
+ printf("\tformat: %d\n",letohs(header->format));
+ if (letohs(header->format)!=1) {
if (!quiet)
fprintf(stderr,_("\t\tformat field should 1 (pcm tag)\n"));
if (fix) {
- header->format = 1;
+ header->format = htoles(1);
if (!quiet)
cerr << _("\t\tfixed\n");
}
}
- printf(_("\tchannels: %d\n"),header->channels);
- if (header->channels!=2 && header->channels!=1) {
+ printf(_("\tchannels: %d\n"),letohs(header->channels));
+ if (letohs(header->channels)!=2 &&
+ letohs(header->channels)!=1) {
if (!quiet)
fprintf(stderr,_("\t\tchannels field should be 1 (mono) or 2 (stereo)\n"));
if (fix) {
@@ -209,28 +224,29 @@
}
}
- printf(_("\tsample rate: %d\n"),header->samplerate);
- if (header->samplerate>48000 || header->samplerate<8000) {
+ printf(_("\tsample rate: %d\n"),letohl(header->samplerate));
+ if (letohl(header->samplerate)>48000 ||
+ letohl(header->samplerate)<8000) {
if (!quiet)
fprintf(stderr,_("\t\tsample rate field should be between 8000 and 48000\n"));
if (fix)
cerr << _("\t\tdon't know which value must be set...\n") << endl;
}
- printf(_("\tbytes/second: %d\n"),header->bytespersec);
+ printf(_("\tbytes/second: %d\n"),letohl(header->bytespersec));
- printf(_("\tbytes/sample: %d\n"),header->bytespersample);
- if (header->bytespersample!=1 &&
- header->bytespersample!=2 &&
- header->bytespersample!=4) {
+ printf(_("\tbytes/sample: %d\n"),letohs(header->bytespersample));
+ if (letohs(header->bytespersample)!=1 &&
+ letohs(header->bytespersample)!=2 &&
+ letohs(header->bytespersample)!=4) {
if (!quiet)
fprintf(stderr,_("\t\t bytes/sample field should be 1, 2 or 4\n"));
if (fix)
cerr << _("\t\tdon't know which value must be set...\n") << endl;
}
- printf(_("\tbits/sample: %d\n"),header->bitspersample);
+ printf(_("\tbits/sample: %d\n"),letohs(header->bitspersample));
printf("\tdata: '%.4s'\n",header->data);
if (strncmp(header->data,"data",4)) {
@@ -243,12 +259,12 @@
}
}
- printf(_("\tdata length: %d\n"),header->datalength);
- if (header->datalength!=f.getSize()-44) {
+ printf(_("\tdata length: %d\n"),letohl(header->datalength));
+ if (letohl(header->datalength)!=f.getSize()-44) {
if (!quiet)
fprintf(stderr,_("\t\tdata length field should be %d\n"),f.getSize()-44);
if (fix) {
- header->datalength = f.getSize()-44;
+ header->datalength = htolel(f.getSize()-44);
if (!quiet)
cerr << _("\t\tfixed\n");
}
|