auto &ids_dims = ids.dims(); int64_t max_length = ids_dims[0]; auto batch_size = ids_dims[1]; auto beam_size = ids_dims[2]; // 从维度中取出三个参数 PADDLE_ENFORCE_NOT_NULL(ids_data, phi::errors::InvalidArgument( "Input(Ids) of gather_tree should not be null."));
PADDLE_ENFORCE_NOT_NULL( parents_data, phi::errors::InvalidArgument( "Input(Parents) of gather_tree should not be null."));
for (int batch = 0; batch < batch_size; batch++) { for (int beam = 0; beam < beam_size; beam++) { auto idx = (max_length - 1) * batch_size * beam_size + batch * beam_size + beam; out_data[idx] = ids_data[idx]; auto parent = parents_data[idx]; // out_data[max_length-1][batch][beam] = ids_data[max_length-1][batch][beam] // auto parent = parents_data[max_length-1][batch][beam]; for (int64_t step = max_length - 2; step >= 0; step--) { PADDLE_ENFORCE_LT( parent, beam_size, phi::errors::InvalidArgument( "The parents must be less than beam size, but received" "parents %d is greater than or equal to beam size %d. ", parent, beam_size));
我使用python的atheris库尝试去fuzz gather_tree这个算子,只需要简单的mutate,就能够收到本漏洞的crash。但是atheris只能Atheris will report a failure if the Python code under test throws an uncaught exception,对于这种segmentation fault,直接导致了线程的crash就没办法自动保存当时的输入,可以选择在代码中手动保存。