I agree, this looks extremely sketchy. Especially because the code is just writing a fully controlled byte in the buffer and incrementing its index.
This would give you a controlled relative write primitive if you can repeatedly call this function in a loop and going OOB.