Changeset: cd78f7ee1ab6 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/cd78f7ee1ab6 Removed Files: monetdb5/modules/mal/Tests/ascii_io2.maltest Modified Files: clients/Tests/MAL-signatures-hge.test clients/Tests/MAL-signatures.test monetdb5/ChangeLog.Dec2023 monetdb5/modules/mal/Tests/All monetdb5/modules/mal/mal_io.c Branch: Dec2023 Log Message:
Removed io.import and io.export. They're not particularly safe, letting the server create and read arbitrary files. diffs (truncated from 345 to 300 lines): diff --git a/clients/Tests/MAL-signatures-hge.test b/clients/Tests/MAL-signatures-hge.test --- a/clients/Tests/MAL-signatures-hge.test +++ b/clients/Tests/MAL-signatures-hge.test @@ -46799,16 +46799,6 @@ pattern inspect.optimizer_stats() (X_0:b OPTstatistics; Get optimizer use statistics, i.e. calls and total time io -export -command io.export(X_0:bat[:any_2], X_1:str):void -IOexport; -Export a BAT as ASCII to a file. If the 'filepath' is not absolute, it@is put into the $DBPATH directory. Success of failure is indicated. -io -import -command io.import(X_0:bat[:any_2], X_1:str):void -IOimport; -Import a BAT from an ASCII dump. The tuples are appended to the@first argument. Its signature must match the dump,@else parsing errors will occur as an exception. -io print pattern io.print(X_0:any_1):void IOprint_val; diff --git a/clients/Tests/MAL-signatures.test b/clients/Tests/MAL-signatures.test --- a/clients/Tests/MAL-signatures.test +++ b/clients/Tests/MAL-signatures.test @@ -35249,16 +35249,6 @@ pattern inspect.optimizer_stats() (X_0:b OPTstatistics; Get optimizer use statistics, i.e. calls and total time io -export -command io.export(X_0:bat[:any_2], X_1:str):void -IOexport; -Export a BAT as ASCII to a file. If the 'filepath' is not absolute, it@is put into the $DBPATH directory. Success of failure is indicated. -io -import -command io.import(X_0:bat[:any_2], X_1:str):void -IOimport; -Import a BAT from an ASCII dump. The tuples are appended to the@first argument. Its signature must match the dump,@else parsing errors will occur as an exception. -io print pattern io.print(X_0:any_1):void IOprint_val; diff --git a/monetdb5/ChangeLog.Dec2023 b/monetdb5/ChangeLog.Dec2023 --- a/monetdb5/ChangeLog.Dec2023 +++ b/monetdb5/ChangeLog.Dec2023 @@ -1,6 +1,9 @@ # ChangeLog file for MonetDB5 # This file is updated with Maddlog +* Wed Dec 6 2023 Sjoerd Mullender <sjo...@acm.org> +- The MAL functions io.import and io.export have been removed. + * Mon Nov 20 2023 Sjoerd Mullender <sjo...@acm.org> - Removed MAL functions bat.getRole and bat.setColumn since the underlying function BATroles was removed. diff --git a/monetdb5/modules/mal/Tests/All b/monetdb5/modules/mal/Tests/All --- a/monetdb5/modules/mal/Tests/All +++ b/monetdb5/modules/mal/Tests/All @@ -20,8 +20,6 @@ imprints # flags is influecend by the Mtest command line -ascii_io2 - mat remoteInit diff --git a/monetdb5/modules/mal/Tests/ascii_io2.maltest b/monetdb5/modules/mal/Tests/ascii_io2.maltest deleted file mode 100644 --- a/monetdb5/modules/mal/Tests/ascii_io2.maltest +++ /dev/null @@ -1,31 +0,0 @@ -statement ok -namebat := bat.new( :str) - -statement ok -bat.append(namebat,"tmpdocs") - -statement ok -bat.append(namebat,"tmpterms") - -query T rowsort -io.printf("#source:%s\n","namebat") ----- -#source:namebat - -statement ok -io.export(namebat, "namebat") - -statement ok -z:= bat.new(:str) - -statement ok -io.import(z,"namebat") - -query IT rowsort -io.print(z) ----- -0 -tmpdocs -1 -tmpterms - diff --git a/monetdb5/modules/mal/mal_io.c b/monetdb5/modules/mal/mal_io.c --- a/monetdb5/modules/mal/mal_io.c +++ b/monetdb5/modules/mal/mal_io.c @@ -612,231 +612,6 @@ IOtable(Client cntxt, MalBlkPtr mb, MalS return MAL_SUCCEED; } - -/* - * Bulk export/loading - * To simplify conversion between versions and to interface with other - * applications, we use a simple import/export operation. - * - * The conversion routine assumes space in the buffer for storing the result. - */ -/* - * A BAT can be saved in Monet format using the export command. - * It is of particular use in preparing an ASCII version for migration. - * The exported file is saved in the context of the directory - * where the server was started unless an absolute file name was - * presented. - */ - -static str -IOexport(void *ret, bat *bid, str *fnme) -{ - BAT *b; - stream *s; - - (void) ret; - if ((b = BATdescriptor(*bid)) == NULL) - throw(MAL, "io.export", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); - - s = open_wastream(*fnme); - if (s == NULL) { - BBPunfix(b->batCacheid); - throw(MAL, "io.export", "%s", mnstr_peek_error(NULL)); - } - if (mnstr_errnr(s) != MNSTR_NO__ERROR) { - mnstr_close(s); - BBPunfix(b->batCacheid); - throw(MAL, "io.export", "%s", mnstr_peek_error(NULL)); - } - BATprintcolumns(s, 1, &b); - close_stream(s); - BBPunfix(b->batCacheid); - return MAL_SUCCEED; -} - -/* - * The import command reads a single BAT from an ASCII file produced by export. - */ -static str -IOimport(void *ret, bat *bid, str *fnme) -{ - BAT *b; - ssize_t (*tconvert)(const char *, size_t *, ptr *, bool); - ssize_t n; - size_t bufsize = 2048; /* NIELS:tmp change used to be 1024 */ - char *base, *cur, *end; - char *buf; - ptr t = 0; - size_t lt = 0; - FILE *fp = MT_fopen(*fnme, "r"); - char msg[BUFSIZ]; - - (void) ret; - if (fp == NULL) - throw(MAL, "io.import", RUNTIME_FILE_NOT_FOUND ":%s", *fnme); - if ((b = BATdescriptor(*bid)) == NULL) { - fclose(fp); - throw(MAL, "io.import", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); - } - - tconvert = BATatoms[BATttype(b)].atomFromStr; - /* - * Open the file. Memory map it to minimize buffering problems. - */ - int fn; - struct stat st; - - buf = (char *) GDKmalloc(bufsize); - if (buf == NULL) { - BBPunfix(b->batCacheid); - fclose(fp); - throw(MAL, "io.import", SQLSTATE(HY013) MAL_MALLOC_FAIL); - } - - if ((fn = fileno(fp)) <= 0) { - BBPunfix(b->batCacheid); - fclose(fp); - GDKfree(buf); - throw(MAL, "io.import", OPERATION_FAILED ": fileno()"); - } - if (fstat(fn, &st) != 0) { - BBPunfix(b->batCacheid); - fclose(fp); - GDKfree(buf); - throw(MAL, "io.import", OPERATION_FAILED ": fstat()"); - } - - (void) fclose(fp); - if (st.st_size <= 0) { - BBPunfix(b->batCacheid); - GDKfree(buf); - throw(MAL, "io.import", OPERATION_FAILED ": empty file"); - } -#if SIZEOF_SIZE_T == SIZEOF_INT - if (st.st_size > 0x7FFFFFFF) { - BBPunfix(b->batCacheid); - GDKfree(buf); - throw(MAL, "io.import", OPERATION_FAILED ": file too large"); - } -#endif - base = cur = GDKmmap(*fnme, MMAP_SEQUENTIAL, (size_t) st.st_size); - if (cur == NULL) { - BBPunfix(b->batCacheid); - GDKfree(buf); - throw(MAL, "io.import", OPERATION_FAILED "GDKmmap()"); - } - end = cur + st.st_size; - - /* Parse a line. Copy it into a buffer. Concat broken lines with a slash. */ - while (cur < end) { - str dst = buf, src = cur, p; - size_t l; - - /* like p = strchr(cur, '\n') but with extra bounds check */ - for (p = cur; p < end && *p != '\n'; p++) ; - l = p - cur; - - if (p < end) { - while (src[l - 1] == '\\') { - if (buf + bufsize < dst + l) { - size_t len = dst - buf; - size_t inc = (size_t) ((dst + l) - buf); - char *tmp = GDKrealloc(buf, bufsize = MAX(inc, bufsize) * 2); - if (tmp == NULL) { - BBPunfix(b->batCacheid); - GDKfree(buf); - GDKfree(t); - GDKmunmap(base, MMAP_SEQUENTIAL, end - base); - throw(MAL, "io.import", - SQLSTATE(HY013) MAL_MALLOC_FAIL); - } - buf = tmp; - dst = buf + len; - } - memcpy(dst, src, l - 1); - dst += l - 1; - src += l + 1; - for (p = src; p < end && *p != '\n'; p++) ; - if (p == end) - break; - l = p - src; - } - } - - if (buf + bufsize < dst + l) { - size_t len = dst - buf; - size_t inc = (size_t) ((dst + l) - buf); - char *tmp = GDKrealloc(buf, bufsize = MAX(inc, bufsize) * 2); - if (tmp == NULL) { - BBPunfix(b->batCacheid); - GDKfree(buf); - GDKfree(t); - GDKmunmap(base, MMAP_SEQUENTIAL, end - base); - throw(MAL, "io.import", SQLSTATE(HY013) MAL_MALLOC_FAIL); - } - buf = tmp; - dst = buf + len; - } - memcpy(dst, src, l); - dst[l] = 0; - cur = p + 1; - /* Parse the line, and insert a BUN. */ - for (p = buf; *p && GDKisspace(*p); p++) ; - if (*p == '#') - continue; - - for (; *p && *p != '['; p++) ; - if (*p) - for (p++; *p && GDKisspace(*p); p++) ; - if (*p == 0) { - BBPunfix(b->batCacheid); - snprintf(msg, sizeof(msg), "error in input %s", buf); - GDKfree(buf); - GDKmunmap(base, MMAP_SEQUENTIAL, end - base); - GDKfree(t); - throw(MAL, "io.import", "%s", msg); - } - n = tconvert(p, <, (ptr *) &t, true); - if (n < 0) { - BBPunfix(b->batCacheid); - snprintf(msg, sizeof(msg), "error in input %s", buf); - GDKfree(buf); - GDKmunmap(base, MMAP_SEQUENTIAL, end - base); - GDKfree(t); - throw(MAL, "io.import", "%s", msg); _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org