From 58d016987d5abacba98596aac173ae0b1302bb12 Mon Sep 17 00:00:00 2001 From: mikefc Date: Thu, 1 Feb 2024 08:44:24 +1000 Subject: [PATCH 1/3] Check for bytes read when parsing from gz files --- src/R-yyjson-parse.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/R-yyjson-parse.c b/src/R-yyjson-parse.c index 933d0c2..58a9403 100644 --- a/src/R-yyjson-parse.c +++ b/src/R-yyjson-parse.c @@ -1961,8 +1961,11 @@ SEXP parse_from_gzfile_(SEXP filename_, SEXP parse_opts_) { fseek(fp, -4, SEEK_END); int32_t uncompressed_len; - fread(&uncompressed_len, 4, 1, fp); + size_t nbytes = fread(&uncompressed_len, 4, 1, fp); fclose(fp); + if (nbytes != 4) { + error("Couldn't read size from end of file: %s", filename); + } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Allocate a buffer to hold the uncompressed file. @@ -1977,8 +1980,11 @@ SEXP parse_from_gzfile_(SEXP filename_, SEXP parse_opts_) { // Uncompress file to buffer //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gzFile gzfp = gzopen(filename, "r"); - gzread(gzfp, (void *)buf, uncompressed_len); + int N = gzread(gzfp, (void *)buf, uncompressed_len); gzclose(gzfp); + if (N != uncompressed_len) { + error("Incorrect number of bytes read. Expected %i, read %i", uncompressed_len, N); + } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Parse buffer as string From b31b22d7eb5708d06a2c38cb3c0a7d7fc6f7c3f7 Mon Sep 17 00:00:00 2001 From: mikefc Date: Thu, 1 Feb 2024 09:01:19 +1000 Subject: [PATCH 2/3] Fix expected bytes from fread() --- src/R-yyjson-parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/R-yyjson-parse.c b/src/R-yyjson-parse.c index 58a9403..15e5e7c 100644 --- a/src/R-yyjson-parse.c +++ b/src/R-yyjson-parse.c @@ -1961,7 +1961,7 @@ SEXP parse_from_gzfile_(SEXP filename_, SEXP parse_opts_) { fseek(fp, -4, SEEK_END); int32_t uncompressed_len; - size_t nbytes = fread(&uncompressed_len, 4, 1, fp); + size_t nbytes = fread(&uncompressed_len, 1, 4, fp); fclose(fp); if (nbytes != 4) { error("Couldn't read size from end of file: %s", filename); From fe8386819d6dee8208a34747719f6c332b4e7a93 Mon Sep 17 00:00:00 2001 From: mikefc Date: Fri, 2 Feb 2024 07:04:30 +1000 Subject: [PATCH 3/3] Create requirements.txt [no ci] --- .devcontainer/requirements.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .devcontainer/requirements.txt diff --git a/.devcontainer/requirements.txt b/.devcontainer/requirements.txt new file mode 100644 index 0000000..f74186d --- /dev/null +++ b/.devcontainer/requirements.txt @@ -0,0 +1,14 @@ +pybryt +pylint +datascience +otter-grader +numpy +pandas +scipy +folium>=0.9.1 +matplotlib +ipywidgets>=7.0.0 +bqplot +nbinteract>=0.0.12 +okpy +scikit-learn