Skip to content

Commit cc55a07

Browse files
committed
mt2exm: warn of incompatible GXMT versions
1 parent 6531bd1 commit cc55a07

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

doc/gromox-mt2exm.8

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ only.
7474
\fB\-\-skip\-rules\fP
7575
Skip executing rules (when \-D is used).
7676
.SH Exit status notes
77-
An input stream of length zero is treated as an invalid GXMT stream (rather
78-
than a stream that is valid but has no commands in it), and leads to a non-zero
79-
exit status.
77+
All input streams must have at least a valid magic signature (first eight
78+
bytes) \(em an input stream of length zero is treated as invalid rather than as
79+
a valid stream without any commands.
8080
.SH Examples
8181
PFF import to a private mailbox:
8282
.PP

tools/mt2exm.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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+
97110
static 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

Comments
 (0)