Skip to content

Commit f4b70fb

Browse files
committed
ECC-2167 improved check on computed offset
1 parent fc7a7d8 commit f4b70fb

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/eccodes/grib_api.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,11 +1346,13 @@ void grib_get_reduced_row(long pl, double lon_first, double lon_last, long* npoi
13461346
void grib_get_reduced_row_p(long pl, double lon_first, double lon_last, long* npoints, double* olon_first, double* olon_last);
13471347

13481348
/* read products */
1349-
int wmo_read_any_from_file_with_offset(FILE* f, void* buffer, size_t* len, off_t* offset);
13501349
int wmo_read_any_from_file(FILE* f, void* buffer, size_t* len);
13511350
int wmo_read_grib_from_file(FILE* f, void* buffer, size_t* len);
13521351
int wmo_read_bufr_from_file(FILE* f, void* buffer, size_t* len);
13531352
int wmo_read_gts_from_file(FILE* f, void* buffer, size_t* len);
1353+
/* if f support ftell, offset is updated with the absolute position within the file, */
1354+
/* otherwise, it accumulates the position across a series of calls */
1355+
int wmo_read_any_from_file_with_offset(FILE* f, void* buffer, size_t* len, off_t* offset);
13541356
int wmo_read_any_from_stream(void* stream_data, long (*stream_proc)(void*, void* buffer, long len), void* buffer, size_t* len);
13551357

13561358
/* These functions allocate memory for the result so the user is responsible for freeing it */

src/eccodes/grib_io.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ static int ecc_read_any(reader* r, int no_alloc, int grib_ok, int bufr_ok, int h
879879
case GRIB:
880880
if (grib_ok) {
881881
err = read_GRIB(r, no_alloc);
882-
if (r->offset == -5) {
882+
if (r->offset < 0) {
883883
r->offset = offset - 4;
884884
}
885885
return err == GRIB_END_OF_FILE ? GRIB_PREMATURE_END_OF_FILE : err; /* Premature EOF */
@@ -889,7 +889,7 @@ static int ecc_read_any(reader* r, int no_alloc, int grib_ok, int bufr_ok, int h
889889
case BUFR:
890890
if (bufr_ok) {
891891
err = read_BUFR(r, no_alloc);
892-
if (r->offset == -5) {
892+
if (r->offset < 0) {
893893
r->offset = offset - 4;
894894
}
895895
return err == GRIB_END_OF_FILE ? GRIB_PREMATURE_END_OF_FILE : err; /* Premature EOF */
@@ -913,7 +913,7 @@ static int ecc_read_any(reader* r, int no_alloc, int grib_ok, int bufr_ok, int h
913913
case BUDG:
914914
if (grib_ok) {
915915
err = read_PSEUDO(r, "BUDG", no_alloc);
916-
if (r->offset == -5) {
916+
if (r->offset < 0) {
917917
r->offset = offset - 4;
918918
}
919919
return err == GRIB_END_OF_FILE ? GRIB_PREMATURE_END_OF_FILE : err; /* Premature EOF */
@@ -922,7 +922,7 @@ static int ecc_read_any(reader* r, int no_alloc, int grib_ok, int bufr_ok, int h
922922
case DIAG:
923923
if (grib_ok) {
924924
err = read_PSEUDO(r, "DIAG", no_alloc);
925-
if (r->offset == -5) {
925+
if (r->offset < 0) {
926926
r->offset = offset - 4;
927927
}
928928
return err == GRIB_END_OF_FILE ? GRIB_PREMATURE_END_OF_FILE : err; /* Premature EOF */
@@ -931,7 +931,7 @@ static int ecc_read_any(reader* r, int no_alloc, int grib_ok, int bufr_ok, int h
931931
case TIDE:
932932
if (grib_ok) {
933933
err = read_PSEUDO(r, "TIDE", no_alloc);
934-
if (r->offset == -5) {
934+
if (r->offset < 0) {
935935
r->offset = offset - 4;
936936
}
937937
return err == GRIB_END_OF_FILE ? GRIB_PREMATURE_END_OF_FILE : err; /* Premature EOF */

0 commit comments

Comments
 (0)