SDL_RenderReadPixels only reads pixel from texture of window

I believe this is a bug
even if I use SDL_SetRenderTarget before SDL_RenderReadPixels, it still gets pixel from window.

What is more weird is that the size is stretched by the texture of renderer target. For example:
I have a SDL_Texture * mytex, size 400x400, created with flag SDL_TEXTUREACCESS_TARGET.
My window’s size is 640x480.
//first do drawing on mytex
SDL_SetRenderTarget(renderer, mytex); //return value is 0
SDL_RenderReadPixels(renderer, &rect, …); //rect is {0, 0, 640, 480}, return value is also 0
The result is that it reads the pixel of 400x400 area of the window, and rest part are black.

What’s more, if the size of mytex is 800x800 (larger than window), and set rect to {0, 0, 800, 800}, SDL_RenderReadPixels will crash.