@@ -67,7 +67,7 @@ private int32_t mprint(struct magic_set *, struct magic *);
67
67
private int32_t moffset (struct magic_set * , struct magic * );
68
68
private void mdebug (uint32_t , const char * , size_t );
69
69
private int mcopy (struct magic_set * , union VALUETYPE * , int , int ,
70
- const unsigned char * , uint32_t , size_t , size_t );
70
+ const unsigned char * , uint32_t , size_t , struct magic * );
71
71
private int mconvert (struct magic_set * , struct magic * , int );
72
72
private int print_sep (struct magic_set * , int );
73
73
private int handle_annotation (struct magic_set * , struct magic * );
@@ -1038,7 +1038,7 @@ mdebug(uint32_t offset, const char *str, size_t len)
1038
1038
1039
1039
private int
1040
1040
mcopy (struct magic_set * ms , union VALUETYPE * p , int type , int indir ,
1041
- const unsigned char * s , uint32_t offset , size_t nbytes , size_t linecnt )
1041
+ const unsigned char * s , uint32_t offset , size_t nbytes , struct magic * m )
1042
1042
{
1043
1043
/*
1044
1044
* Note: FILE_SEARCH and FILE_REGEX do not actually copy
@@ -1058,15 +1058,24 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
1058
1058
const char * last ; /* end of search region */
1059
1059
const char * buf ; /* start of search region */
1060
1060
const char * end ;
1061
- size_t lines ;
1061
+ size_t lines , linecnt , bytecnt ;
1062
1062
1063
+ linecnt = m -> str_range ;
1064
+ bytecnt = linecnt * 80 ;
1065
+
1066
+ if (bytecnt == 0 ) {
1067
+ bytecnt = 8192 ;
1068
+ }
1069
+ if (bytecnt > nbytes ) {
1070
+ bytecnt = nbytes ;
1071
+ }
1063
1072
if (s == NULL ) {
1064
1073
ms -> search .s_len = 0 ;
1065
1074
ms -> search .s = NULL ;
1066
1075
return 0 ;
1067
1076
}
1068
1077
buf = RCAST (const char * , s ) + offset ;
1069
- end = last = RCAST (const char * , s ) + nbytes ;
1078
+ end = last = RCAST (const char * , s ) + bytecnt ;
1070
1079
/* mget() guarantees buf <= last */
1071
1080
for (lines = linecnt , b = buf ; lines && b < end &&
1072
1081
((b = CAST (const char * ,
@@ -1079,7 +1088,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
1079
1088
b ++ ;
1080
1089
}
1081
1090
if (lines )
1082
- last = RCAST (const char * , s ) + nbytes ;
1091
+ last = RCAST (const char * , s ) + bytecnt ;
1083
1092
1084
1093
ms -> search .s = buf ;
1085
1094
ms -> search .s_len = last - buf ;
@@ -1150,7 +1159,6 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
1150
1159
int * need_separator , int * returnval )
1151
1160
{
1152
1161
uint32_t soffset , offset = ms -> offset ;
1153
- uint32_t count = m -> str_range ;
1154
1162
int rv , oneed_separator , in_type ;
1155
1163
char * sbuf , * rbuf ;
1156
1164
union VALUETYPE * p = & ms -> ms_value ;
@@ -1162,13 +1170,12 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
1162
1170
}
1163
1171
1164
1172
if (mcopy (ms , p , m -> type , m -> flag & INDIR , s , (uint32_t )(offset + o ),
1165
- (uint32_t )nbytes , count ) == -1 )
1173
+ (uint32_t )nbytes , m ) == -1 )
1166
1174
return -1 ;
1167
1175
1168
1176
if ((ms -> flags & MAGIC_DEBUG ) != 0 ) {
1169
1177
fprintf (stderr , "mget(type=%d, flag=%x, offset=%u, o=%zu, "
1170
- "nbytes=%zu, count=%u)\n" , m -> type , m -> flag , offset , o ,
1171
- nbytes , count );
1178
+ "nbytes=%zu)\n" , m -> type , m -> flag , offset , o , nbytes );
1172
1179
mdebug (offset , (char * )(void * )p , sizeof (union VALUETYPE ));
1173
1180
}
1174
1181
@@ -1661,7 +1668,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
1661
1668
if ((ms -> flags & MAGIC_DEBUG ) != 0 )
1662
1669
fprintf (stderr , "indirect +offs=%u\n" , offset );
1663
1670
}
1664
- if (mcopy (ms , p , m -> type , 0 , s , offset , nbytes , count ) == -1 )
1671
+ if (mcopy (ms , p , m -> type , 0 , s , offset , nbytes , m ) == -1 )
1665
1672
return -1 ;
1666
1673
ms -> offset = offset ;
1667
1674
@@ -2093,7 +2100,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
2093
2100
zval * retval ;
2094
2101
zval * subpats ;
2095
2102
char * haystack ;
2096
-
2103
+
2097
2104
MAKE_STD_ZVAL (retval );
2098
2105
ALLOC_INIT_ZVAL (subpats );
2099
2106
0 commit comments