ID:122034
 
Not a bug
BYOND Version:493
Operating System:Linux
Web Browser:Internet Explorer 9.0
Applies to:Dream Daemon
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
I have a proc designed to remove html tags all together from a line of text. I use this to ensure players can only use so many characters in a line of text, I know there is a flaw in this which is why I also limit the total length of the text.
For some reason I'm getting this message:
proc name: truelength (/proc/truelength)
source file: System.dm,69
usr: Jadow (/mob/PC)
src: null
call stack:
truelength(BUG: Out of memory!
"")
Jadow (/mob/PC): Guild Change Title()

Backtrace for BYOND 493.1116 on Linux:
Generated at Mon Dec 19 08:49:23 2011

DreamDaemon [0x8048000, 0x0], [0x8048000, 0x804a708]
libc.so.6 0x72b90, 0x72bbf (memcpy)
libc.so.6 [0xb76b3000, 0x0], 0x2a5f0
libc.so.6 0x72b90, 0x72bbf (memcpy)
libbyond.so [0xb7b0b000, 0x0], 0x25dd0f
libbyond.so [0xb7b0b000, 0x0], 0x28da14
libbyond.so [0xb7b0b000, 0x0], 0x2747f1
libbyond.so [0xb7b0b000, 0x0], 0x28e0eb
libbyond.so 0x28e470, 0x28e595
libbyond.so [0xb7b0b000, 0x0], 0x257bcc
libbyond.so 0x31bfe0, 0x31c13c
libbyond.so 0x2ef410, 0x2ef646
DreamDaemon [0x8048000, 0x0], [0x8048000, 0x804a203]
libc.so.6 0x16370, 0x16455 (__libc_start_main)
DreamDaemon [0x8048000, 0x8049b9c], [0x8048000, 0x8049cd1]

To help the BYOND developers debug this, please send the above trace as part
of a very detailed bug report: http://www.byond.com/members/?command=view_tracker&tracker=1

Mon Dec 19 08:52:11 2011
World opened on network port 2286.
Welcome BYOND! (4.0 Public Version 493.1116)
The BYOND hub reports that port 2286 is reachable.
BUG: Crashing due to an illegal operation!
proc name: truelength (/proc/truelength)
source file: System.dm,69
usr: Jadow (/mob/PC)
src: null
call stack:
truelength(BUG: Out of memory!
"")
Jadow (/mob/PC): Guild Change Title()

Backtrace for BYOND 493.1116 on Linux:
Generated at Mon Dec 19 08:53:36 2011

DreamDaemon [0x8048000, 0x0], [0x8048000, 0x804a708]
libc.so.6 0x72b90, 0x72bbf (memcpy)
libc.so.6 [0xb769b000, 0x0], 0x2a5f0
libc.so.6 0x72b90, 0x72bbf (memcpy)
libbyond.so [0xb7af3000, 0x0], 0x25dd0f
libbyond.so [0xb7af3000, 0x0], 0x28da14
libbyond.so [0xb7af3000, 0x0], 0x2747f1
libbyond.so [0xb7af3000, 0x0], 0x28e0eb
libbyond.so 0x28e470, 0x28e595
libbyond.so [0xb7af3000, 0x0], 0x257bcc
libbyond.so 0x31bfe0, 0x31c13c
libbyond.so 0x2ef410, 0x2ef646
DreamDaemon [0x8048000, 0x0], [0x8048000, 0x804a203]
libc.so.6 0x16370, 0x16455 (__libc_start_main)
DreamDaemon [0x8048000, 0x8049b9c], [0x8048000, 0x8049cd1]

To help the BYOND developers debug this, please send the above trace as part
of a very detailed bug report: http://www.byond.com/members/?command=view_tracker&tracker=1



//EDIT

After contacting the person 'Jadow' I've uncovered the html code he was attempting to use and have tested it myself.

html:
<FONT COLOR="#800000">A</FONT><FONT COLOR="#972a08">r</FONT><FONT COLOR="#ae5311">r</FONT><FONT COLOR="#c47d19">o</FONT><FONT COLOR="#daa520">w</FONT><FONT COLOR="#e0b64d">-</FONT><FONT COLOR="#e6c77a">-</FONT><FONT COLOR="#edd7a6">-</FONT><FONT COLOR="#f3e8d3">)</FONT><FONT COLOR="#f8f8ff">-</FONT>


This caused no issues on private testing.

However, seems to cause an issue when the player attempts it.

//END EDIT

It's occured twice in a row, not sure why.

Numbered Steps to Reproduce Problem:
As far as I can tell, it's caused by a specific player; I've been unable to create or recreate it.

Code Snippet (if applicable) to Reproduce Problem:
The proc causing the issue:


proc
truelength(T as text)
set background=1
if(!T)return
hamlegs
if(!T)return
if(!findtextEx(T,"<")) return T
if(findtextEx(T,"<")&&findtextEx(T,">"))
var/I=lentext(T)
var/F=findtextEx(T,"<")
var/L=findtextEx(T,">")
I++
if(!F)return T
if(F>1)
T=copytext(T,1,F)+copytext(T,L+1,I)// line #69
else
T=copytext(T,L+1,I)
if(!findtextEx(T,"<")) return T
if(findtextEx(T,"<")&&findtextEx(T,">"))
goto hamlegs
return
return T
else
return T
return
return


and the verb leading to the proc:

mob/Guild_Leader
verb
Guild_Change_Title()
set category = "Guild"
var/list/Menu = list()
for(var/mob/M in world)
if(!M.client) continue
if(M.in_guild)
if(M.guild_name_html == usr.guild_name_html)
Menu.Add(M)
var/mob/M = input("Change Who's Title?","Guild Change Title") as null | anything in Menu
if(!M)return
if(M.guild_leader&&M!=usr)
usr<< "You cannot change this person's title."
return
if(M.guild_rank==usr.guild_rank&&M!=usr)
usr<< "You cannot change this person's title."
return
if(istype(M,/mob))
switch(input("What title do you wish to give [M]?")in list("Custom","Cancel"))
if("Custom")
switch(alert("Do you wish to Alter their Title?","Change Title","Yes","No"))
if("Yes")
var/new_title = input("What do you wish their Title to be called?(HTML Allowed)","Custom Title",\M.title) as text | null
if(Check_For_Text(new_title,BAD_HTML_TAGS) == TRUE)
alert("The title may not contain line breaks or size changing fonts.")
return
if(Check_For_Text(new_title,BAD_WORDS) == TRUE)
alert("Your title may not have bad words in it.")
return
if(Check_For_Text(new_title,BAD_LINK) == TRUE)
alert("You cannot advertise here.")
return
if(Check_For_Size(new_title)==TRUE)return
if(lentext(truelength(new_title))>36)
spawn() alert("Title too long.")
return
if(lentext(new_title) > 930)
spawn() alert("Your message can not exceed 930 characters.")
new_title = copytext(new_title,1,930)
M.title = new_title
for(var/mob/X in world)
if(X.guild_name == src.guild_name)
X << "<font color = #BB0EDA>Guild Information:</font> [M] has been granted the title of [new_title]!"
if("No")
return
if("Cancel")
return


Expected Results:
The return of the line of text without html tags.

Actual Results:
Works perfectly fine most of the time.

Does the problem occur:
Every time? Or how often?
Only twice, one after another.
In other games?
Only one game I'm aware of, asked a few people.
In other user accounts?
It's only happend with one player; The host has been the same since I implamented the proc.
On other computers?
It's been tested on several computers and operating systems, without failure. First time happening on the current.

When does the problem NOT occur?
First occurance, never happend before.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked?
I've seen one other 'illegal operation' crash before, but it was before I made the proc it's happening in now, and on a different version of byond.

Workarounds:
Not sure if there are any.
There is no bug here; your code is gobbling up memory because of a design flaw. There are several problems in your code: You are abusing goto; you are performing the same checks over and over unnecessarily; the I var is totally unnecessary; you misspelled "whose".

But the main issue causing your problems is that when checking for the < and > characters, you are not ensuring that > comes after <. The HTML that your player gave you should not cause your routine to fail, but if that ) character became a >, it would. If F is greater than L at any time in your loop, then line 69 could cause some unpredictable behavior.