Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/robin/gh-1847-resync-error'
Browse files Browse the repository at this point in the history
* origin/topic/robin/gh-1847-resync-error:
  Fix resynchronization issue with trimmed input.
  Add missing printer support for exception values.
  • Loading branch information
rsmmr committed Sep 11, 2024
2 parents f78dd89 + c6177f9 commit da36054
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 155 deletions.
20 changes: 20 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
1.12.0-dev.77 | 2024-09-11 08:18:38 +0200

* GH-1847: Fix resynchronization issue with trimmed input. (Robin Sommer, Corelight)

When input had been trimmed, `View::advanceToNextData` could end up
returning a view starting ahead of the valid area.

* Add missing printer support for exception values. (Robin Sommer, Corelight)

* GH-1860: Fix parsing for vectors of literals. (Robin Sommer, Corelight)

This was broken in two ways:

1. with the `(LITERAL)[]` syntax, the parser would not recognize literals
using type constructors
2. with the syntax `LITERAL[]`, we'd try to store the parsed value
into a vector

* Fix error message. (Robin Sommer, Corelight)

1.12.0-dev.71 | 2024-09-06 16:29:02 +0200

* Move some `scoped_id` out for better locations. (Evan Typanski, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.0-dev.71
1.12.0-dev.77
13 changes: 10 additions & 3 deletions hilti/runtime/src/types/stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,16 @@ bool View::isComplete() const {
}

View View::advanceToNextData() const {
// Start search for next data chunk at the next byte. This
// ensures that we always advance by at least one byte.
auto i = _begin + 1;
SafeConstIterator i;

if ( _begin.offset() < _begin.chain()->offset() )
// We're at a position that has been trimmed already, move to current
// head of the stream
i = _begin.chain()->begin();
else
// Start search for next data chunk at the next byte. This
// ensures that we always advance by at least one byte.
i = _begin + 1;

auto* c = i.chunk(); // Pointer to the currently looked at chunk.

Expand Down
2 changes: 2 additions & 0 deletions hilti/toolchain/src/compiler/printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ struct Printer : visitor::PreOrder {

void operator()(ctor::Error* n) final { _out << "error(\"" << n->value() << "\")"; }

void operator()(ctor::Exception* n) final { _out << "exception(" << n->value() << ")"; }

void operator()(ctor::Interval* n) final { _out << "interval_ns(" << n->value().nanoseconds() << ")"; }

void operator()(ctor::List* n) final { _out << '[' << std::make_pair(n->value(), ", ") << ']'; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Field "hook void __on_0x25_sync_advance(uint<64> offset) &needed-by-feature="uses_sync_advance";" -> null
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Field "hook void __on_0x25_synced() &needed-by-feature="synchronization";" -> null
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Field "hook void __on_0x25_undelivered(uint<64> seq, bytes data);" -> null
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Function "method extern method view<stream> foo::P0::parse1(inout value_ref<stream> __data, optional<view<stream>> __cur = Null, optional<spicy_rt::UnitContext> __context) &needed-by-feature="is_filter" &needed-by-feature="supports_sinks" &static { # "<...>/default-parser-functions.spicy:12:11-12:17" local value_ref<foo::P0> __unit = value_ref(default<const foo::P0>()); local view<stream> __ncur = __cur ? (*__cur) : cast<view<stream>>((*__data)); local int<64> __lahead = 0; local iterator<stream> __lahead_end; local optional<hilti::RecoverableFailure> __error = Null; # "<...>/default-parser-functions.spicy:12:11-12:17" # Begin parsing production: Unit: foo__P0 -> (__ncur, __lahead, __lahead_end, __error) = (*__unit).__parse_stage1(__data, begin(__ncur), __ncur, True, __lahead, __lahead_end, __error); # End parsing production: Unit: foo__P0 -> if ( __error ) throw ; return __ncur; }" -> null (removing declaration for unused function)
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Function "method extern method view<stream> foo::P0::parse2(inout value_ref<foo::P0> __unit, inout value_ref<stream> __data, optional<view<stream>> __cur = Null, optional<spicy_rt::UnitContext> __context) &needed-by-feature="is_filter" &needed-by-feature="supports_sinks" &static { # "<...>/default-parser-functions.spicy:12:11-12:17" local view<stream> __ncur = __cur ? (*__cur) : cast<view<stream>>((*__data)); local int<64> __lahead = 0; local iterator<stream> __lahead_end; local optional<hilti::RecoverableFailure> __error = Null; # "<...>/default-parser-functions.spicy:12:11-12:17" # Begin parsing production: Unit: foo__P0 -> (__ncur, __lahead, __lahead_end, __error) = (*__unit).__parse_stage1(__data, begin(__ncur), __ncur, True, __lahead, __lahead_end, __error); # End parsing production: Unit: foo__P0 -> if ( __error ) throw ; return __ncur; }" -> null (removing declaration for unused function)
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Function "method extern method view<stream> foo::P0::parse3(inout value_ref<spicy_rt::ParsedUnit> __gunit, inout value_ref<stream> __data, optional<view<stream>> __cur = Null, optional<spicy_rt::UnitContext> __context) &needed-by-feature="is_filter" &needed-by-feature="supports_sinks" &static { # "<...>/default-parser-functions.spicy:12:11-12:17" local value_ref<foo::P0> __unit = value_ref(default<const foo::P0>()); spicy_rt::initializeParsedUnit((*__gunit), __unit, typeinfo(foo::P0)); local view<stream> __ncur = __cur ? (*__cur) : cast<view<stream>>((*__data)); local int<64> __lahead = 0; local iterator<stream> __lahead_end; local optional<hilti::RecoverableFailure> __error = Null; # "<...>/default-parser-functions.spicy:12:11-12:17" # Begin parsing production: Unit: foo__P0 -> (__ncur, __lahead, __lahead_end, __error) = (*__unit).__parse_stage1(__data, begin(__ncur), __ncur, True, __lahead, __lahead_end, __error); # End parsing production: Unit: foo__P0 -> if ( __error ) throw ; return __ncur; }" -> null (removing declaration for unused function)
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Function "method extern method view<stream> foo::P0::parse1(inout value_ref<stream> __data, optional<view<stream>> __cur = Null, optional<spicy_rt::UnitContext> __context) &needed-by-feature="is_filter" &needed-by-feature="supports_sinks" &static { # "<...>/default-parser-functions.spicy:12:11-12:17" local value_ref<foo::P0> __unit = value_ref(default<const foo::P0>()); local view<stream> __ncur = __cur ? (*__cur) : cast<view<stream>>((*__data)); local int<64> __lahead = 0; local iterator<stream> __lahead_end; local optional<hilti::RecoverableFailure> __error = Null; # "<...>/default-parser-functions.spicy:12:11-12:17" # Begin parsing production: Unit: foo__P0 -> (__ncur, __lahead, __lahead_end, __error) = (*__unit).__parse_stage1(__data, begin(__ncur), __ncur, True, __lahead, __lahead_end, __error); # End parsing production: Unit: foo__P0 -> if ( __error ) throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error)))); return __ncur; }" -> null (removing declaration for unused function)
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Function "method extern method view<stream> foo::P0::parse2(inout value_ref<foo::P0> __unit, inout value_ref<stream> __data, optional<view<stream>> __cur = Null, optional<spicy_rt::UnitContext> __context) &needed-by-feature="is_filter" &needed-by-feature="supports_sinks" &static { # "<...>/default-parser-functions.spicy:12:11-12:17" local view<stream> __ncur = __cur ? (*__cur) : cast<view<stream>>((*__data)); local int<64> __lahead = 0; local iterator<stream> __lahead_end; local optional<hilti::RecoverableFailure> __error = Null; # "<...>/default-parser-functions.spicy:12:11-12:17" # Begin parsing production: Unit: foo__P0 -> (__ncur, __lahead, __lahead_end, __error) = (*__unit).__parse_stage1(__data, begin(__ncur), __ncur, True, __lahead, __lahead_end, __error); # End parsing production: Unit: foo__P0 -> if ( __error ) throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error)))); return __ncur; }" -> null (removing declaration for unused function)
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Function "method extern method view<stream> foo::P0::parse3(inout value_ref<spicy_rt::ParsedUnit> __gunit, inout value_ref<stream> __data, optional<view<stream>> __cur = Null, optional<spicy_rt::UnitContext> __context) &needed-by-feature="is_filter" &needed-by-feature="supports_sinks" &static { # "<...>/default-parser-functions.spicy:12:11-12:17" local value_ref<foo::P0> __unit = value_ref(default<const foo::P0>()); spicy_rt::initializeParsedUnit((*__gunit), __unit, typeinfo(foo::P0)); local view<stream> __ncur = __cur ? (*__cur) : cast<view<stream>>((*__data)); local int<64> __lahead = 0; local iterator<stream> __lahead_end; local optional<hilti::RecoverableFailure> __error = Null; # "<...>/default-parser-functions.spicy:12:11-12:17" # Begin parsing production: Unit: foo__P0 -> (__ncur, __lahead, __lahead_end, __error) = (*__unit).__parse_stage1(__data, begin(__ncur), __ncur, True, __lahead, __lahead_end, __error); # End parsing production: Unit: foo__P0 -> if ( __error ) throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error)))); return __ncur; }" -> null (removing declaration for unused function)
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Function "method method tuple<const view<stream>, int<64>, const iterator<stream>, optional<hilti::RecoverableFailure>> foo::P0::__parse_foo__P0_stage2(inout value_ref<stream> __data, iterator<stream> __begin, copy view<stream> __cur, copy bool __trim, copy int<64> __lah, copy iterator<stream> __lahe, copy optional<hilti::RecoverableFailure> __error) { # "<...>/default-parser-functions.spicy:12:11-12:17" local tuple<view<stream>, int<64>, const iterator<stream>, optional<hilti::RecoverableFailure>> __result; (*self).__error = __error; default<void>(); __error = (*self).__error; hilti::debugDedent("spicy"); __result = (__cur, __lah, __lahe, __error); return __result; }" -> null (removing declaration for unused function)
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] declaration::Function "method method tuple<const view<stream>, int<64>, const iterator<stream>, optional<hilti::RecoverableFailure>> foo::P0::__parse_stage1(inout value_ref<stream> __data, iterator<stream> __begin, copy view<stream> __cur, copy bool __trim, copy int<64> __lah, copy iterator<stream> __lahe, copy optional<hilti::RecoverableFailure> __error) { # "<...>/default-parser-functions.spicy:12:11-12:17" local tuple<view<stream>, int<64>, const iterator<stream>, optional<hilti::RecoverableFailure>> __result; try { hilti::debugIndent("spicy"); local iterator<stream> __begin = begin(__cur); (*self).__error = __error; default<void>(); __error = (*self).__error; local strong_ref<stream> filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__P0_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { default<void>(); (*self).__error = __error; default<void>(); __error = (*self).__error; throw; } (*self).__error = __error; default<void>(); __error = (*self).__error; return __result; }" -> null (removing declaration for unused function)
[debug/optimizer] [default-parser-functions.spicy:12:11-12:17] operator_::struct_::MemberCall "(*self).__on_0x25_done()" -> expression::Ctor "default<void>()" (replacing call to unimplemented method with default value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ method extern method view<stream> foo::P0::parse1(inout value_ref<stream> __data


if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand Down Expand Up @@ -324,7 +324,7 @@ method extern method view<stream> foo::P0::parse3(inout value_ref<spicy_rt::Pars


if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand All @@ -350,7 +350,7 @@ method extern method view<stream> foo::P0::parse2(inout value_ref<P0> __unit, in


if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand Down Expand Up @@ -542,7 +542,7 @@ method extern method view<stream> foo::P1::parse1(inout value_ref<stream> __data


if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand Down Expand Up @@ -570,7 +570,7 @@ method extern method view<stream> foo::P1::parse3(inout value_ref<spicy_rt::Pars


if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand All @@ -596,7 +596,7 @@ method extern method view<stream> foo::P1::parse2(inout value_ref<P1> __unit, in


if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand Down Expand Up @@ -860,7 +860,7 @@ method extern method view<stream> foo::P2::parse1(inout value_ref<stream> __data


if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand Down Expand Up @@ -888,7 +888,7 @@ method extern method view<stream> foo::P2::parse3(inout value_ref<spicy_rt::Pars


if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand All @@ -914,7 +914,7 @@ method extern method view<stream> foo::P2::parse2(inout value_ref<P2> __unit, in


if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ method extern method view<stream> foo::P1::parse1(inout value_ref<stream> __data
# End parsing production: Unit: foo__P1 ->

if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand All @@ -129,7 +129,7 @@ method extern method view<stream> foo::P1::parse3(inout value_ref<spicy_rt::Pars
# End parsing production: Unit: foo__P1 ->

if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand All @@ -147,7 +147,7 @@ method extern method view<stream> foo::P1::parse2(inout value_ref<P1> __unit, in
# End parsing production: Unit: foo__P1 ->

if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ method extern method view<stream> foo::P2::parse1(inout value_ref<stream> __data
# End parsing production: Unit: foo__P2 -> x y

if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand All @@ -265,7 +265,7 @@ method extern method view<stream> foo::P2::parse3(inout value_ref<spicy_rt::Pars
# End parsing production: Unit: foo__P2 -> x y

if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand All @@ -283,7 +283,7 @@ method extern method view<stream> foo::P2::parse2(inout value_ref<P2> __unit, in
# End parsing production: Unit: foo__P2 -> x y

if ( __error )
throw ;
throw exception("successful synchronization never confirmed: %s" % (hilti::exception_what((*__error))));

return __ncur;
}
Expand Down
Loading

0 comments on commit da36054

Please sign in to comment.