Opened 7 years ago
Closed 7 years ago
#754 closed defect (fixed)
Exception in generate_sample with 0 as sample size
Reported by: | Gaurav Arora | Owned by: | Olly Betts |
---|---|---|---|
Priority: | normal | Milestone: | 1.4.6 |
Component: | Omega | Version: | 1.4.5 |
Severity: | normal | Keywords: | GoodFirstBug |
Cc: | Blocked By: | ||
Blocking: | Operating System: | All |
Description
I was trying to input sample size as 0 to generate function and this lead to an exception. We should probably handle this case
Continuing. Exception: basic_string::replace: pos (which is 18446744073709551615) > this->size() (which is 2) [Inferior 1 (process 3121) exited with code 01]
Exception occurs at https://github.com/xapian/xapian/blob/356ea64fa21c7d6d5974e5e8dac796c000fe84e6/xapian-applications/omega/sample.cc#L54 line
output.replace(maxlen - ind.size(), string::npos, ind);
Size of ind is 3 as i sent "..." and maxlen is zero, so it tries to access -ve index of string. Which should be prevented.
Probably better to return an empty string if sample size provided is smaller than ind. But i am waiting for feedback from community before proposing and writing a patch
Change History (6)
comment:1 by , 7 years ago
Component: | Other → Omega |
---|---|
Milestone: | → 1.4.6 |
Version: | → 1.4.5 |
comment:2 by , 7 years ago
Keywords: | GoodFirstBug added |
---|
comment:4 by , 7 years ago
Fixed in git master by d21a213e95c8a010da8bb7031160a66100ba07c0. Leaving open until backported.
comment:5 by , 7 years ago
It'd be good to check that the dynamic snippet code in core handles this case sensibly too.
I don't see anything in xapian-core/tests/api_snippets.cc
testing what happens if the requested snippet length is 0 or a sufficiently small value that there's no useful snippet to show, so that would be a useful addition still.
comment:6 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Backported for 1.4.6 in 65039dc1e7da321ccd29559e012a9917d535a003.
Created #759 for adding similar tests for MSet::snippet()
in xapian-core.
Returning an empty string sounds good to me.
It'd be good to check that the dynamic snippet code in core handles this case sensibly too.