|
@@ -57,6 +57,10 @@ struct zinfo_file {
|
57
|
57
|
unsigned int num_entries;
|
58
|
58
|
};
|
59
|
59
|
|
|
60
|
+static unsigned long align ( unsigned long value, unsigned long align ) {
|
|
61
|
+ return ( ( value + align - 1 ) & ~( align - 1 ) );
|
|
62
|
+}
|
|
63
|
+
|
60
|
64
|
static int read_file ( const char *filename, void **buf, size_t *len ) {
|
61
|
65
|
FILE *file;
|
62
|
66
|
struct stat stat;
|
|
@@ -140,14 +144,13 @@ static int process_zinfo_copy ( struct input_file *input,
|
140
|
144
|
struct zinfo_copy *copy = &zinfo->copy;
|
141
|
145
|
size_t offset = copy->offset;
|
142
|
146
|
size_t len = copy->len;
|
143
|
|
- unsigned int align = copy->align;
|
144
|
147
|
|
145
|
148
|
if ( ( offset + len ) > input->len ) {
|
146
|
149
|
fprintf ( stderr, "Input buffer overrun on copy\n" );
|
147
|
150
|
return -1;
|
148
|
151
|
}
|
149
|
152
|
|
150
|
|
- output->len = ( ( output->len + align - 1 ) & ~( align - 1 ) );
|
|
153
|
+ output->len = align ( output->len, copy->align );
|
151
|
154
|
if ( ( output->len + len ) > output->max_len ) {
|
152
|
155
|
fprintf ( stderr, "Output buffer overrun on copy\n" );
|
153
|
156
|
return -1;
|
|
@@ -170,7 +173,6 @@ static int process_zinfo_pack ( struct input_file *input,
|
170
|
173
|
struct zinfo_pack *pack = &zinfo->pack;
|
171
|
174
|
size_t offset = pack->offset;
|
172
|
175
|
size_t len = pack->len;
|
173
|
|
- unsigned int align = pack->align;
|
174
|
176
|
unsigned long packed_len;
|
175
|
177
|
|
176
|
178
|
if ( ( offset + len ) > input->len ) {
|
|
@@ -178,7 +180,7 @@ static int process_zinfo_pack ( struct input_file *input,
|
178
|
180
|
return -1;
|
179
|
181
|
}
|
180
|
182
|
|
181
|
|
- output->len = ( ( output->len + align - 1 ) & ~( align - 1 ) );
|
|
183
|
+ output->len = align ( output->len, pack->align );
|
182
|
184
|
if ( output->len > output->max_len ) {
|
183
|
185
|
fprintf ( stderr, "Output buffer overrun on pack\n" );
|
184
|
186
|
return -1;
|
|
@@ -222,8 +224,9 @@ static int process_zinfo_subtract ( struct input_file *input,
|
222
|
224
|
}
|
223
|
225
|
|
224
|
226
|
target = ( output->buf + offset );
|
225
|
|
- delta = ( ( output->len / subtract->divisor ) -
|
226
|
|
- ( input->len / subtract->divisor ) );
|
|
227
|
+ delta = ( ( align ( output->len, subtract->divisor ) -
|
|
228
|
+ align ( input->len, subtract->divisor ) )
|
|
229
|
+ / subtract->divisor );
|
227
|
230
|
|
228
|
231
|
switch ( datasize ) {
|
229
|
232
|
case 1: {
|
|
@@ -251,7 +254,7 @@ static int process_zinfo_subtract ( struct input_file *input,
|
251
|
254
|
}
|
252
|
255
|
|
253
|
256
|
if ( DEBUG ) {
|
254
|
|
- fprintf ( stderr, "SUBx [%#zx,%#zx) (%#lx+(%#lx/%#lx)-(%#lx/%#lx)) = %#lx\n",
|
|
257
|
+ fprintf ( stderr, "SUBx [%#zx,%#zx) (%#lx+(%#lx/%#x)-(%#lx/%#x)) = %#lx\n",
|
255
|
258
|
offset, ( offset + datasize ), old, output->len, subtract->divisor,
|
256
|
259
|
input->len, subtract->divisor, new );
|
257
|
260
|
}
|