test: address AMF depth review feedback

This commit is contained in:
YuLi
2026-07-24 15:05:15 -07:00
parent 09a3cd9a5a
commit 5f6fe223ca
2 changed files with 15 additions and 4 deletions

View File

@@ -93,6 +93,10 @@ private:
public: public:
explicit DepthGuard(AMFDecoder &decoder); explicit DepthGuard(AMFDecoder &decoder);
~DepthGuard(); ~DepthGuard();
DepthGuard(const DepthGuard &) = delete;
DepthGuard(DepthGuard &&) = delete;
DepthGuard &operator=(const DepthGuard &) = delete;
DepthGuard &operator=(DepthGuard &&) = delete;
private: private:
AMFDecoder &_decoder; AMFDecoder &_decoder;

View File

@@ -8,7 +8,7 @@
* may be found in the AUTHORS file in the root of the source tree. * may be found in the AUTHORS file in the root of the source tree.
*/ */
#include <cassert> #include <iostream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@@ -34,17 +34,24 @@ int main() {
{ {
BufferLikeString input(make_nested_object(64)); BufferLikeString input(make_nested_object(64));
AMFDecoder decoder(input, 0); AMFDecoder decoder(input, 0);
assert(decoder.load<AMFValue>().type() == AMF_OBJECT); if (decoder.load<AMFValue>().type() != AMF_OBJECT) {
cerr << "AMF object at the nesting limit was not decoded" << endl;
return 1;
}
} }
{ {
BufferLikeString input(make_nested_object(65)); BufferLikeString input(make_nested_object(65));
AMFDecoder decoder(input, 0); AMFDecoder decoder(input, 0);
bool depth_rejected = false;
try { try {
decoder.load<AMFValue>(); decoder.load<AMFValue>();
assert(false);
} catch (const runtime_error &ex) { } catch (const runtime_error &ex) {
assert(string(ex.what()) == "Maximum AMF nesting depth exceeded"); depth_rejected = string(ex.what()) == "Maximum AMF nesting depth exceeded";
}
if (!depth_rejected) {
cerr << "AMF object beyond the nesting limit was not rejected" << endl;
return 2;
} }
} }