You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When there is a carriage return separating the base64 image from text the error does not occur.
How to reproduce
Place a large base64 image into markup adjacent to plain markup, try to generate html. Timeout.
This is my markup.![image.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABrEAAAJUCAYAAACyig2eAAAgAElEQVR4XuydB2AUZdrH/9uSQCD03kFUioIgUoRTBAEVBXvXs9x3nufZ61nA3vvZe0exgIqAHUUEqdJ7E6SEDiF98z3POzOb2c1udhOWGOA/3xeT7M68885v3nAwv/......................
I have not been able to determine the exact length of base64 string required to cause the issue. It's large, but less than 1Mb.
Possible solution
Cache the string if it's multibyte.....
public function __construct(string $line)
{
if (! \mb_check_encoding($line, 'UTF-8')) {
throw new UnexpectedEncodingException('Unexpected encoding - UTF-8 or ASCII was expected');
}
$this->line = $line;
$this->length = \mb_strlen($line, 'UTF-8') ?: 0;
$this->isMultibyte = $this->length !== \strlen($line);
$this->lastTabPosition = $this->isMultibyte ? \mb_strrpos($line, "\t", 0, 'UTF-8') : \strrpos($line, "\t");
// Cache the entire string if it's multibyte for faster access
if ($this->isMultibyte) {
$this->charCache = \preg_split('//u', $line, -1, PREG_SPLIT_NO_EMPTY);
}
}
public function getCurrentCharacter(): ?string
{
if ($this->currentPosition >= $this->length) {
return null;
}
if ($this->isMultibyte) {
return $this->charCache[$this->currentPosition] ?? null;
}
return $this->line[$this->currentPosition];
}
Additional context
No response
Did this project help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered:
I think I tried your suggested approach many years ago and found that it was slower? But I could be misremembering that, so I do think it's worthwhile to revisit this.
Maybe we should also add some configuration options to limit/avoid parsing of excessively long lines?
Version(s) affected
2.4.2
Description
When I have a large base64 image in markdown directly adjacent to other text, Cursor.php exceeds execution time at line 180
When there is a carriage return separating the base64 image from text the error does not occur.
How to reproduce
Place a large base64 image into markup adjacent to plain markup, try to generate html. Timeout.
This is my markup.![image.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABrEAAAJUCAYAAACyig2eAAAgAElEQVR4XuydB2AUZdrH/9uSQCD03kFUioIgUoRTBAEVBXvXs9x3nufZ61nA3vvZe0exgIqAHUUEqdJ7E6SEDiF98z3POzOb2c1udhOWGOA/3xeT7M68885v3nAwv/......................
I have not been able to determine the exact length of base64 string required to cause the issue. It's large, but less than 1Mb.
Possible solution
Cache the string if it's multibyte.....
Additional context
No response
Did this project help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: