Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 326270

Summary: [tcf] request of small amount of memory causes Byte64 conversion to "overflow" passed buffer
Product: [Tools] TCF Reporter: Kirk Beitz <kirk.beitz>
Component: CoreAssignee: Project Inbox <dsdp.tm.tcf-inbox>
Status: RESOLVED INVALID QA Contact: Martin Oberhuber <mober.at+eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug, eugene
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
patch to MemoryProxy.java that bulletproofs the call to JSON.toByteArray() kirk.beitz: review?

Description Kirk Beitz CLA 2010-09-27 03:22:23 EDT
Build Identifier: 

in org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote in MemoryProxy.java , MemoryProxy.MemContext#get()$MemoryCommand#done() can end up with a perfectly valid 3-byte buffer that should be filled with the Byte64 filled string containing the values to place in the buffer.

however, the algorithm of JSON.toByteArray() will choke on this input.

(it's possible that the value passed back is not properly terminated, or that JSON didn't take this into account; but it the conversion routine throws IllegalArgumentException if the buffer is not big enough.)

I will attach a patch that causes this not to happen.

Reproducible: Always

Steps to Reproduce:
1. create a plug-in that uses TCF
2. attempt to get a 3-byte chunk of memory that will fail

if the portion of the code using TCF to retrieve memory fails with an unhandled IllegalArgumentException in the call made from JSON.toByteArray() => FAIL
Comment 1 Kirk Beitz CLA 2010-09-27 03:23:12 EDT
Created attachment 179604 [details]
patch to MemoryProxy.java that bulletproofs the call to JSON.toByteArray()
Comment 2 Eugene Tarassov CLA 2010-09-27 13:56:24 EDT
I cannot reproduce the error. Reading 3-byte chunk of memory appears to work fine in the current code.

It looks like you are using agent that is different from one in Eclipse repository, and it produces malformed BASE64 strings. Can you send a value of BASE64 string that causes JSON.toByteArray() to fail?

If the string is indeed malformed, throwing IllegalArgumentException is correct behavior. BTW, what does the exception message say?
Comment 3 Kirk Beitz CLA 2010-09-27 14:10:25 EDT
the problem occurs on a target which disallows the reading of the 3 bytes in question due to access restriction.  an error message is getting sent back.

the String being sent back is something like "TLTVAA==" ... 8 characters, with the last two being "=" signs.  when the Byte64 translator parses this, it starts with an outlen of 8/4*3 or 6, and then reduces the size for each of the "=" signs so outlen is 4 … which is still larger than the input buffer which is 3.
Comment 4 Eugene Tarassov CLA 2010-09-27 14:27:49 EDT
So the agent does misbehave. Even if it can read memory only in 4-byte chucks, it should transmit only requested number of bytes. Otherwise it is a communication error and an the exception seems to be the best way to report it.

Looks like agent problem to me.
Comment 5 Kirk Beitz CLA 2010-09-27 15:06:49 EDT
i will see about what the agent is doing.  sounds like the expectation is that it should only be returning a JSON string of 4 bytes that gets turned into the buffer of 3 that i want.
Comment 6 Doug Schaefer CLA 2011-05-17 10:49:30 EDT
Moving bugs to new home for IP log.