@@ -58,7 +58,7 @@ private int32_t mprint(struct magic_set *, struct magic *);
58
58
private int32_t moffset (struct magic_set * , struct magic * );
59
59
private void mdebug (uint32_t , const char * , size_t );
60
60
private int mcopy (struct magic_set * , union VALUETYPE * , int , int ,
61
- const unsigned char * , uint32_t , size_t , size_t );
61
+ const unsigned char * , uint32_t , size_t , struct magic * );
62
62
private int mconvert (struct magic_set * , struct magic * , int );
63
63
private int print_sep (struct magic_set * , int );
64
64
private int handle_annotation (struct magic_set * , struct magic * );
@@ -1003,7 +1003,7 @@ mdebug(uint32_t offset, const char *str, size_t len)
1003
1003
1004
1004
private int
1005
1005
mcopy (struct magic_set * ms , union VALUETYPE * p , int type , int indir ,
1006
- const unsigned char * s , uint32_t offset , size_t nbytes , size_t linecnt )
1006
+ const unsigned char * s , uint32_t offset , size_t nbytes , struct magic * m )
1007
1007
{
1008
1008
/*
1009
1009
* Note: FILE_SEARCH and FILE_REGEX do not actually copy
@@ -1023,15 +1023,24 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
1023
1023
const char * last ; /* end of search region */
1024
1024
const char * buf ; /* start of search region */
1025
1025
const char * end ;
1026
- size_t lines ;
1026
+ size_t lines , linecnt , bytecnt ;
1027
1027
1028
+ linecnt = m -> str_range ;
1029
+ bytecnt = linecnt * 80 ;
1030
+
1031
+ if (bytecnt == 0 ) {
1032
+ bytecnt = 8192 ;
1033
+ }
1034
+ if (bytecnt > nbytes ) {
1035
+ bytecnt = nbytes ;
1036
+ }
1028
1037
if (s == NULL ) {
1029
1038
ms -> search .s_len = 0 ;
1030
1039
ms -> search .s = NULL ;
1031
1040
return 0 ;
1032
1041
}
1033
1042
buf = RCAST (const char * , s ) + offset ;
1034
- end = last = RCAST (const char * , s ) + nbytes ;
1043
+ end = last = RCAST (const char * , s ) + bytecnt ;
1035
1044
/* mget() guarantees buf <= last */
1036
1045
for (lines = linecnt , b = buf ; lines && b < end &&
1037
1046
((b = CAST (const char * ,
@@ -1044,7 +1053,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
1044
1053
b ++ ;
1045
1054
}
1046
1055
if (lines )
1047
- last = RCAST (const char * , s ) + nbytes ;
1056
+ last = RCAST (const char * , s ) + bytecnt ;
1048
1057
1049
1058
ms -> search .s = buf ;
1050
1059
ms -> search .s_len = last - buf ;
@@ -1118,7 +1127,6 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
1118
1127
int * need_separator , int * returnval )
1119
1128
{
1120
1129
uint32_t soffset , offset = ms -> offset ;
1121
- uint32_t count = m -> str_range ;
1122
1130
int rv , oneed_separator ;
1123
1131
char * sbuf , * rbuf ;
1124
1132
union VALUETYPE * p = & ms -> ms_value ;
@@ -1130,13 +1138,12 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
1130
1138
}
1131
1139
1132
1140
if (mcopy (ms , p , m -> type , m -> flag & INDIR , s , (uint32_t )(offset + o ),
1133
- (uint32_t )nbytes , count ) == -1 )
1141
+ (uint32_t )nbytes , m ) == -1 )
1134
1142
return -1 ;
1135
1143
1136
1144
if ((ms -> flags & MAGIC_DEBUG ) != 0 ) {
1137
1145
fprintf (stderr , "mget(type=%d, flag=%x, offset=%u, o=%zu, "
1138
- "nbytes=%zu, count=%u)\n" , m -> type , m -> flag , offset , o ,
1139
- nbytes , count );
1146
+ "nbytes=%zu)\n" , m -> type , m -> flag , offset , o , nbytes );
1140
1147
mdebug (offset , (char * )(void * )p , sizeof (union VALUETYPE ));
1141
1148
}
1142
1149
@@ -1627,7 +1634,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
1627
1634
if ((ms -> flags & MAGIC_DEBUG ) != 0 )
1628
1635
fprintf (stderr , "indirect +offs=%u\n" , offset );
1629
1636
}
1630
- if (mcopy (ms , p , m -> type , 0 , s , offset , nbytes , count ) == -1 )
1637
+ if (mcopy (ms , p , m -> type , 0 , s , offset , nbytes , m ) == -1 )
1631
1638
return -1 ;
1632
1639
ms -> offset = offset ;
1633
1640
@@ -2057,7 +2064,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
2057
2064
zval * retval ;
2058
2065
zval * subpats ;
2059
2066
char * haystack ;
2060
-
2067
+
2061
2068
MAKE_STD_ZVAL (retval );
2062
2069
ALLOC_INIT_ZVAL (subpats );
2063
2070
0 commit comments