WordPress/wordpress-playground

Stack Overflow: memory access out of bounds

Closed this issue · 5 comments

Fix: #870


This might be a reincarnation of #169

To reproduce:

  1. Open https://playground.wordpress.net/?plugin=web-stories&php-extension-bundle=kitchen-sink
  2. Go to Dashboard -> Stories
  3. Hover over a template and click on "Use template"
  4. This would normally trigger a REST API POST request with a (relatively large) body
  5. See memory access out of bounds error in console

Are there some body size limits with playground that one should be aware of?

Possibly related: #416

Are there some body size limits with playground that one should be aware of?

Not that I know of, other than the PHP memory limit which should result in a PHP Fatal Error, not wasm crash. That's definitely a bug in Playground. Some memcpy call must be missing a boundary check, or something to that effect.

This is the same bug as #870, and is fixed by the same code.

Potentially related Emscripten issue: Automatically growing the stack. Passing a large request body or response body via stack may be hitting the default stack size of, I think, 1MB.

The issue is indeed a related to stack size. Clicking "Use template" calls wasm_set_request_body with a body string that's 153KB large which is too much for the current WASM build. #870 explores a potential fix by storing the request body on HEAP:

		const size = this[__private__dont__use].lengthBytesUTF8(body);
		const addr = this.malloc(size + 1);
		this[__private__dont__use].stringToUTF8(body, addr, size + 1);
		this[__private__dont__use].ccall(
			'wasm_set_request_body',
			null,
			[NUMBER],
			[addr]
		);

I'm not convinced about encoding the body bytes as UTF8 so the details may change, but there's a good chance the heap approach would fix this problem.

@swissspidy this should be fixed! :-) Thank you for reporting, please let me know about any other issues you stumble upon.

CleanShot 2024-02-02 at 15 35 17@2x