Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/archivers/arc/files/patch-arcio.c
16461 views
1
--- arcio.c.orig 2013-06-27 02:00:19 UTC
2
+++ arcio.c
3
@@ -35,6 +35,7 @@ readhdr(hdr, f) /* read a header from an archive */
4
#endif
5
char name[FNLEN]; /* filename buffer */
6
int try = 0;/* retry counter */
7
+ int hdrlen;
8
static int first = 1; /* true only on first read */
9
10
if (!f) /* if archive didn't open */
11
@@ -44,7 +45,7 @@ readhdr(hdr, f) /* read a header from an archive */
12
return 0; /* then signal end of archive */
13
14
if (hdrver != ARCMARK) { /* check archive validity */
15
- if (warn) {
16
+ if (arcwarn) {
17
printf("An entry in %s has a bad header.\n", arcname);
18
nerrs++;
19
}
20
@@ -65,10 +66,10 @@ readhdr(hdr, f) /* read a header from an archive */
21
if (feof(f) && first)
22
arcdie("%s is not an archive", arcname);
23
24
- if (changing && warn)
25
+ if (changing && arcwarn)
26
arcdie("%s is corrupted -- changes disallowed", arcname);
27
28
- if (warn)
29
+ if (arcwarn)
30
printf(" %d bytes skipped.\n", try);
31
32
if (feof(f))
33
@@ -90,33 +91,40 @@ readhdr(hdr, f) /* read a header from an archive */
34
printf("I think you need a newer version of ARC.\n");
35
exit(1);
36
}
37
+
38
/* amount to read depends on header type */
39
+ if (hdrver == 1) {
40
+ hdrlen = 23; /* old style is shorter */
41
+ } else {
42
+ hdrlen = 27;
43
+ }
44
45
- if (hdrver == 1) { /* old style is shorter */
46
- if (fread(hdr, sizeof(struct heads) - sizeof(long int), 1, f) != 1)
47
- arcdie("%s was truncated", arcname);
48
- hdrver = 2; /* convert header to new format */
49
- hdr->length = hdr->size; /* size is same when not
50
- * packed */
51
- } else
52
-#if MSDOS
53
- if (fread(hdr, sizeof(struct heads), 1, f) != 1)
54
- arcdie("%s was truncated", arcname);
55
-#else
56
- if (fread(dummy, 27, 1, f) != 1)
57
- arcdie("%s was truncated", arcname);
58
+ if (fread(dummy, hdrlen, 1, f) != 1)
59
+ arcdie("%s was truncated", arcname);
60
61
for (i = 0; i < FNLEN; hdr->name[i] = dummy[i], i++);
62
+ hdr->name[FNLEN - 1] = 0; /* ensure 0 termination */
63
#if _MTS
64
(void) atoe(hdr->name, strlen(hdr->name));
65
#endif
66
+ if (strchr(hdr->name, CUTOFF) != NULL)
67
+ arcdie("%s contains illegal filename %s", arcname, hdr->name);
68
+
69
for (i = 0, hdr->size=0; i<4; hdr->size<<=8, hdr->size += dummy[16-i], i++);
70
hdr->date = (short) ((dummy[18] << 8) + dummy[17]);
71
hdr->time = (short) ((dummy[20] << 8) + dummy[19]);
72
hdr->crc = (short) ((dummy[22] << 8) + dummy[21]);
73
- for (i = 0, hdr->length=0; i<4; hdr->length<<=8, hdr->length += dummy[26-i], i++);
74
-#endif
75
76
+ if (hdrver == 1) {
77
+ hdrver = 2; /* convert header to new format */
78
+ hdr->length = hdr->size; /* size is same when not
79
+ * packed */
80
+ } else {
81
+ for (i = 0, hdr->length=0; i<4; hdr->length<<=8, hdr->length += dummy[26-i], i++);
82
+ }
83
+
84
+ if (hdr->size < 0)
85
+ arcdie("Invalid header in archive %s", arcname);
86
if (hdr->date > olddate
87
|| (hdr->date == olddate && hdr->time > oldtime)) {
88
olddate = hdr->date;
89
90