C# sdk demo SDKERR_VIDEO_NOTREADY

After some searching I found invalid use of pin_ptr in zoom_sdk_c_sharp_wrap/zoom_sdk_dotnet_wrap_util.h.
Function ZOOM_SDK_DOTNET_WRAP::PlatformString2WChar uses PtrToStringChars and pins the resulting pointer on the managed string data. So far so good.

But pin_ptr pins only as long as the variable is in scope. So as soon as PlatformString2WChar returns, which is done directly after pinning, the pointer is no longer pinned. But the pointer is still used as parameter for SDKAuth which is called afterwards. And it is not pinned anymore. So any garbage collection can lead to overwriting of parts of the string. And we get error 11. The fact that we only see the problem in SDKAuth is that the token string is strongly verified and it is larger than usual strings like user names or passwords.

from pin_ptr (C++/CLI) | Microsoft Docs
An object is pinned only while a pin_ptr points to it. The object is no longer pinned when its pinning pointer goes out of scope, or is set to nullptr. After the pin_ptr goes out of scope, the object that was pinned can be moved in the heap by the garbage collector. Any native pointers that still point to the object will not be updated, and de-referencing one of them could raise an unrecoverable exception.

Original code in C# Wrapper:

	static const wchar_t* PlatformString2WChar(String^ str)
	{
		if (nullptr == str)
		{
			return NULL;
		}

		pin_ptr<const wchar_t> wch = PtrToStringChars(str);
		return wch;
	}

Bug fixed version:

#include <msclr\marshal.h>
#include <msclr\marshal_cppstd.h>
	static std::wstring PlatformString2WCharBugFix(String^ str)
	{
		if (nullptr == str)
		{
			return std::wstring();
		}
		return msclr::interop::marshal_as<std::wstring>(str);
	}

But as you see you need to change the signature of the function in order to avoid manual memory deallocation. This way there are no memory leaks and no references of unpinned managed pointers. But you need to adjust all code parts where this function is called:

PlatformString2WChar(someStr)

to something like:

PlatformString2WCharBugFix(someStr).c_str()

Should be enough as long as the string is not used after someStr goes out of scope.

@roland.oldenburg Please check if this fixes the problem on the machine that is heavily affected by this problem.

@Michael_Condon Please forward to developer.

@andrez Amazing job! And it sounds plausible to me that this is an issue. It also may explain other issues that I encounter now and then: Sometimes automatic renamings triggered from the app are somewhat “ignored”.

But either way, @Michael_Condon
The Auth 11 problem is solved!!! Yes!!! …Easy when you know what to look for…
The affected machine has last been “time synchronized” in April! So… it was a little out of sync. Its time was 5 seconds ahead.

And that made the jwt token invalid. By the time I was using/testing it, it was valid again because it took me more than 5 seconds to do so… :rofl: :joy: :crazy_face:

Maybe you guys could give others a hint when they have issues with jwt token. Like “check your system time”. Thanks for your support still.

And: It still feels like there is an open issue with pin_ptr handling…
But for now I am happy.

Hey @roland.oldenburg,

Ahh yes that makes sense! That is a good suggestion, we will keep that in mind :slight_smile:
I am happy to hear that it is now working for you! Please let us know if you run into anything else.

Thanks!
Michael

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.