Nvidia OpenCL driver crash when an invalid context is passed

When I pass a random value to
clCreateCommandQueue(random_context_value, device, NULL, NULL),

App crashes in the Nvidia OpenCL driver, but from spec, it should return an CL_INVALID_CONTEXT error.

Pass other invalid CL handles to OpenCL API aslo causes crash.

Is this a bug of Nvidia OpenCL driver?

Yes, but it’s a hard-to-avoid bug. There’s really no way for the driver to know if a pointer you pass in is garbage without trying to access it, or keeping a list somewhere of all possible valid pointers and then checking this list on every call. My guess is that they’re not doing that, so if your pointer points to an invalid location, the driver tries to access it, and you get a memory access violation.