Skip to content

Commit

Permalink
replace assert with an exception to avoid crashing the process
Browse files Browse the repository at this point in the history
Signed-off-by: Gal Salomon <[email protected]>
  • Loading branch information
galsalomon66 committed Mar 1, 2024
1 parent 1ae458f commit 071146c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
17 changes: 11 additions & 6 deletions include/s3select.h
Original file line number Diff line number Diff line change
Expand Up @@ -2730,24 +2730,29 @@ class csv_object : public base_s3object
m_error_description = "escaped_char_missing failure while csv parsing";
return -1;
}
catch(io::error::escaped_string_not_closed& err)
catch(io::error::escaped_string_not_closed& err)
{
m_error_description = "escaped_string_not_closed failure while csv parsing";
return -1;
}
catch(io::error::line_length_limit_exceeded& err)
catch(io::error::line_length_limit_exceeded& err)
{
m_error_description = "line_length_limit_exceeded failure while csv parsing";
return -1;
}
catch(io::error::with_file_name& err)
catch(io::error::missmatch_of_begin_end& err)
{
m_error_description = "with_file_name failure while csv parsing";
m_error_description = "missmatch_of_begin_end failure while csv parsing" + std::string(err.what());
return -1;
}
catch(io::error::with_file_line& err)
catch(io::error::missmatch_end& err)
{
m_error_description = "with_file_line failure while csv parsing";
m_error_description = "missmatch_end failure while csv parsing" + std::string(err.what());
return -1;
}
catch(io::error::with_file_name& err)
{
m_error_description = "with_file_name failure while csv parsing";
return -1;
}
catch(std::exception& e)
Expand Down
67 changes: 64 additions & 3 deletions include/s3select_csv_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,53 @@ namespace io{
, file_line, file_name);
}
};

struct missmatch_of_begin_end :
base,
with_file_name,
with_file_line{
int begin=-1,end=-1;
void set_begin_end(int b,int e){
begin=b;
end=e;
}

void format_error_message()const override{
std::snprintf(error_message_buffer, sizeof(error_message_buffer),
"***missmatch_of_begin_end*** Line number %d in file \"%s\" begin{%d} > end{%d}"
,file_line, file_name,begin,end);
}
};

struct missmatch_end :
base,
with_file_name,
with_file_line{
int end=-1;
int block_size=-1;
void set_end_block(int e,int b){
end = e;
block_size = b;
}
void format_error_message()const override{
std::snprintf(error_message_buffer, sizeof(error_message_buffer),
"***missmatch_end*** Line number %d in file \"%s\" end{%d} block{%d}"
,file_line, file_name, end, block_size);
}
};


struct line_is_null :
base,
with_file_name,
with_file_line{
void format_error_message()const override{
std::snprintf(error_message_buffer, sizeof(error_message_buffer),
"***line is NULL*** Line number %d in file \"%s\""
,file_line, file_name);
}
};

}

namespace detail{
Expand Down Expand Up @@ -133,7 +180,11 @@ namespace io{

void chop_next_column(char*&line, char*&col_begin, char*&col_end, char& col_delimiter, char& quote, char& escape_char)
{
assert(line != nullptr);
if(line == NULL)
{
io::error::line_is_null err;
throw err;
}

col_begin = line;
// the col_begin + (... - col_begin) removes the constness
Expand Down Expand Up @@ -312,8 +363,18 @@ class CSVParser

++file_line;

assert(data_begin < data_end);
assert(data_end <= block_len*2);
if(data_begin > data_end)
{
io::error::missmatch_of_begin_end err;
err.set_begin_end(data_begin,data_end);
throw err;
}
if(data_end > block_len*2)
{
io::error::missmatch_end err;
err.set_end_block(data_end,block_len*2);
throw err;
}

if(data_begin >= block_len)
{
Expand Down

0 comments on commit 071146c

Please sign in to comment.