1111#include < utility>
1212#include < fmt/format.h>
1313#include < json/value.h>
14+ #include < libHX/ctype_helper.h>
1415#include < libHX/endian.h>
1516#include < libHX/io.h>
1617#include < libHX/option.h>
@@ -94,6 +95,18 @@ static void filter_folder_map(gi_folder_map_t &fmap)
9495 p.second .fid_to = rop_util_make_eid_ex (1 , p.second .fid_to );
9596}
9697
98+ static void validate_magic (const char *magic)
99+ {
100+ if (memcmp (magic, " GXMT" , 4 ) != 0 || !HX_isdigit (magic[4 ]) ||
101+ !HX_isdigit (magic[5 ]) || !HX_isdigit (magic[6 ]) ||
102+ !HX_isdigit (magic[7 ]))
103+ throw YError (" PG-1127: Unrecognized input format. GXMT0004 file signature is missing." );
104+ if (memcmp (&magic[4 ], " 0004" , 4 ) == 0 )
105+ return ;
106+ throw YError (" PG-1127: Input is from an unsupported version. "
107+ " Observed signature \" %.8s\" , but only \" GXMT0004\" is understood." , magic);
108+ }
109+
97110static int exm_read_base_maps ()
98111{
99112 errno = 0 ;
@@ -103,8 +116,7 @@ static int exm_read_base_maps()
103116 return 0 ;
104117 if (ret < 0 || static_cast <size_t >(ret) != std::size (magic))
105118 throw YError (" PG-1126: %s" , strerror_eof (errno));
106- if (memcmp (magic, " GXMT0004" , 8 ) != 0 )
107- throw YError (" PG-1127: Unrecognized input format" );
119+ validate_magic (magic);
108120 ret = HXio_fullread (STDIN_FILENO, &g_splice, sizeof (g_splice));
109121 if (ret < 0 || static_cast <size_t >(ret) != sizeof (g_splice))
110122 throw YError (" PG-1120: %s" , strerror_eof (errno));
0 commit comments