summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Zoulas <christos@zoulas.com>2023-02-09 17:45:19 +0000
committerChristos Zoulas <christos@zoulas.com>2023-02-09 17:45:19 +0000
commitf7a65dbf1739a8f8671621e41c5648d1f7e9f6ae (patch)
tree3759ad28e2687e787d570a8423ac3385478cc483
parentc019f3c109cdf6606be265b8039f002d81d996bb (diff)
downloadfile-git-f7a65dbf1739a8f8671621e41c5648d1f7e9f6ae.tar.gz
bump notes section size to read to 128M (Vincent Michalkovic) and make it
configurable. Delete unused constants.
-rw-r--r--doc/file.man15
-rw-r--r--src/file.c4
-rw-r--r--src/file.h4
-rw-r--r--src/magic.c8
-rw-r--r--src/readelf.c11
5 files changed, 25 insertions, 17 deletions
diff --git a/doc/file.man b/doc/file.man
index caa656d0..e536690e 100644
--- a/doc/file.man
+++ b/doc/file.man
@@ -1,4 +1,4 @@
-.\" $File: file.man,v 1.147 2022/10/31 13:22:26 christos Exp $
+.\" $File: file.man,v 1.148 2023/02/09 17:45:19 christos Exp $
.Dd October 26, 2022
.Dt FILE __CSECTION__
.Os
@@ -337,16 +337,17 @@ attempt to preserve the access time of files analyzed, to pretend that
never read them.
.It Fl P , Fl Fl parameter Ar name=value
Set various parameter limits.
-.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
+.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation"
-.It Li bytes Ta 1048576 Ta max number of bytes to read from file
+.It Li bytes Ta 1M Ta max number of bytes to read from file
.It Li elf_notes Ta 256 Ta max ELF notes processed
-.It Li elf_phnum Ta 2048 Ta max ELF program sections processed
-.It Li elf_shnum Ta 32768 Ta max ELF sections processed
-.It Li encoding Ta 65536 Ta max number of bytes to scan for encoding evaluation
+.It Li elf_phnum Ta 2K Ta max ELF program sections processed
+.It Li elf_shnum Ta 32K Ta max ELF sections processed
+.It Li elf_shsize Ta 128MB Ta max ELF section size processed
+.It Li encoding Ta 65K Ta max number of bytes to determine encoding
.It Li indir Ta 50 Ta recursion limit for indirect magic
.It Li name Ta 50 Ta use count limit for name/use magic
-.It Li regex Ta 8192 Ta length limit for regex searches
+.It Li regex Ta 8K Ta length limit for regex searches
.El
.It Fl r , Fl Fl raw
Don't translate unprintable characters to \eooo.
diff --git a/src/file.c b/src/file.c
index c1c3fb91..8d66a48e 100644
--- a/src/file.c
+++ b/src/file.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.213 2022/12/26 17:31:14 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.214 2023/02/09 17:45:19 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -155,6 +155,8 @@ file_private struct {
MAGIC_PARAM_ELF_PHNUM_MAX, 0 },
{ "elf_shnum", 0, FILE_ELF_SHNUM_MAX, "max ELF sections processed",
MAGIC_PARAM_ELF_SHNUM_MAX, 0 },
+ { "elf_shsize", 0, FILE_ELF_SHSIZE_MAX, "max ELF section size",
+ MAGIC_PARAM_ELF_SHSIZE_MAX, 0 },
{ "encoding", 0, FILE_ENCODING_MAX, "max bytes to scan for encoding",
MAGIC_PARAM_ENCODING_MAX, 0 },
{ "indir", 0, FILE_INDIR_MAX, "recursion limit for indirection",
diff --git a/src/file.h b/src/file.h
index 1e1f1e7a..9e37044f 100644
--- a/src/file.h
+++ b/src/file.h
@@ -27,7 +27,7 @@
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.241 2022/12/26 17:31:14 christos Exp $
+ * @(#)$File: file.h,v 1.242 2023/02/09 17:45:19 christos Exp $
*/
#ifndef __file_h__
@@ -482,12 +482,14 @@ struct magic_set {
uint16_t regex_max;
size_t bytes_max; /* number of bytes to read from file */
size_t encoding_max; /* bytes to look for encoding */
+ size_t elf_shsize_max;
#ifndef FILE_BYTES_MAX
# define FILE_BYTES_MAX (7 * 1024 * 1024)/* how much of the file to look at */
#endif /* above 0x6ab0f4 map offset for HelveticaNeue.dfont */
#define FILE_ELF_NOTES_MAX 256
#define FILE_ELF_PHNUM_MAX 2048
#define FILE_ELF_SHNUM_MAX 32768
+#define FILE_ELF_SHSIZE_MAX (128 * 1024 * 1024)
#define FILE_INDIR_MAX 50
#define FILE_NAME_MAX 50
#define FILE_REGEX_MAX 8192
diff --git a/src/magic.c b/src/magic.c
index 80555da3..052f9975 100644
--- a/src/magic.c
+++ b/src/magic.c
@@ -33,7 +33,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: magic.c,v 1.120 2022/12/26 17:31:14 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.121 2023/02/09 17:45:19 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -625,6 +625,9 @@ magic_setparam(struct magic_set *ms, int param, const void *val)
case MAGIC_PARAM_ELF_SHNUM_MAX:
ms->elf_shnum_max = CAST(uint16_t, *CAST(const size_t *, val));
return 0;
+ case MAGIC_PARAM_ELF_SHSIZE_MAX:
+ ms->elf_shsize_max = *CAST(const size_t *, val);
+ return 0;
case MAGIC_PARAM_ELF_NOTES_MAX:
ms->elf_notes_max = CAST(uint16_t, *CAST(const size_t *, val));
return 0;
@@ -661,6 +664,9 @@ magic_getparam(struct magic_set *ms, int param, void *val)
case MAGIC_PARAM_ELF_SHNUM_MAX:
*CAST(size_t *, val) = ms->elf_shnum_max;
return 0;
+ case MAGIC_PARAM_ELF_SHSIZE_MAX:
+ *CAST(size_t *, val) = ms->elf_shsize_max;
+ return 0;
case MAGIC_PARAM_ELF_NOTES_MAX:
*CAST(size_t *, val) = ms->elf_notes_max;
return 0;
diff --git a/src/readelf.c b/src/readelf.c
index 97d14513..8591f14b 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.187 2022/12/26 17:31:14 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.188 2023/02/09 17:45:19 christos Exp $")
#endif
#ifdef BUILTIN_ELF
@@ -60,9 +60,6 @@ file_private uint16_t getu16(int, uint16_t);
file_private uint32_t getu32(int, uint32_t);
file_private uint64_t getu64(int, uint64_t);
-#define MAX_PHNUM 128
-#define MAX_SHNUM 32768
-#define MAX_SHSIZE (64 * 1024 * 1024)
#define SIZE_UNKNOWN CAST(off_t, -1)
file_private int
@@ -1453,10 +1450,10 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
return -1;
return 0;
}
- if (xsh_size > MAX_SHSIZE) {
+ if (xsh_size > ms->elf_shsize_max) {
file_error(ms, errno, "Note section size too "
- "big (%ju > %u)", (uintmax_t)xsh_size,
- MAX_SHSIZE);
+ "big (%ju > %zu)", (uintmax_t)xsh_size,
+ ms->elf_shsize_max);
return -1;
}
if ((nbuf = malloc(xsh_size)) == NULL) {