2026-07-24 14:31:23 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by MIT-like license that can be found in the
|
|
|
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
|
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-07-24 15:05:15 -07:00
|
|
|
#include <iostream>
|
2026-07-24 14:31:23 -07:00
|
|
|
#include <stdexcept>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "Network/Buffer.h"
|
|
|
|
|
#include "Rtmp/amf.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace toolkit;
|
|
|
|
|
|
|
|
|
|
static string make_nested_object(size_t depth) {
|
|
|
|
|
string result;
|
|
|
|
|
for (size_t i = 0; i < depth; ++i) {
|
|
|
|
|
result.append("\x03\x00\x01x", 4);
|
|
|
|
|
}
|
|
|
|
|
result.append("\x05", 1);
|
|
|
|
|
for (size_t i = 0; i < depth; ++i) {
|
|
|
|
|
result.append("\x00\x00\x09", 3);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
{
|
|
|
|
|
BufferLikeString input(make_nested_object(64));
|
|
|
|
|
AMFDecoder decoder(input, 0);
|
2026-07-24 15:05:15 -07:00
|
|
|
if (decoder.load<AMFValue>().type() != AMF_OBJECT) {
|
|
|
|
|
cerr << "AMF object at the nesting limit was not decoded" << endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2026-07-24 14:31:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
BufferLikeString input(make_nested_object(65));
|
|
|
|
|
AMFDecoder decoder(input, 0);
|
2026-07-24 15:05:15 -07:00
|
|
|
bool depth_rejected = false;
|
2026-07-24 14:31:23 -07:00
|
|
|
try {
|
|
|
|
|
decoder.load<AMFValue>();
|
|
|
|
|
} catch (const runtime_error &ex) {
|
2026-07-24 15:05:15 -07:00
|
|
|
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;
|
2026-07-24 14:31:23 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|