PVR-9200T Data Recovery

Now there's an improved version on my github repo: github.com/Pauligrinder/humaxrw/releases/tag/v2026.4

Along with the aforementioned improvements and fixes, I also added a GUI (which I haven't tested because I don't have a disk image or drive at hand right now). Anyway, it uses the cli-app directly so the same stuff should work from that just as well.
 
I've attached ts_align.zip containing the source code
Code:
               char out_name [sizeof (argv [i]) + 2];

               sprintf (out_name, "%sa", argv [i]);
You need to fix this, which will almost certainly cause a memory overwrite unless you have a very short filename.
sizeof(argv[i]) does NOT return the length of the string in argv[i] - it returns the size of "char *", which is a very different thing.
 
Code:
               char out_name [sizeof (argv [i]) + 2];

               sprintf (out_name, "%sa", argv [i]);
You need to fix this, which will almost certainly cause a memory overwrite unless you have a very short filename.
sizeof(argv[i]) does NOT return the length of the string in argv[i] - it returns the size of "char *", which is a very different thing.
It's a classic bug that one, seen similar several times in my career writing software.
 
I believe so, although I've never done it myself or seen it (until now).
It's generally people experienced in other languages moving to C that mix up sizeof and strlen like this. People that learn C as their main language when they start programming as I did don't tend to do this one. 20 years ago (out of a 40 year career) I'd never seen it, but it and similar issues are becoming more common as people move around between languages more and interpreted languages that manage all this for you (like Python) become more common.
 
People that learn C as their main language when they start programming as I did don't tend to do this one.
I taught myself C, after learning Fortran and Basic during my Elec. Eng. degree, and Pascal with an engineering consultancy, and have never found myself using sizeof for strings.
 
Sorry, you are quite right. New version attached.
Yes, but did you actually try to compile it? Clearly not.
You can't use strlen() as the size of an array at compile time as it's a run-time thing. If you're going to do it like this then you need to use malloc()/free() etc.

Outdated knowledge.
 
Last edited:
I taught myself C, after learning Fortran and Basic during my Elec. Eng. degree
Cecil, Basic and self-taught Fortran at school. Then they made us do Pascal as Uni. (* insert stupid comment here *) and then I taught myself C. Then I taught myself properly at first job with a computer company. Far too late in the day for C++ though (again self-taught) but I was doing other stuff by then.
 
Then they made us do Pascal as Uni. (* insert stupid comment here *)
I was forced to use Pascal because a small consultancy company I worked for, occasionally, either used the university mainframe for big simulations or small Apple II with UCSD p-system (ie Pascal) for very small in-house work. That meant some newer simulations were in Pascal. { what a pain }.
 
did you actually try to compile it? Clearly not.
Of course I compiled it. How do you think I produced ts_align.exe? I also tested it.

I used gcc (GCC) 10.3.1 20210520 (for GNAT Community 2021 20210519) with -Wall
Can you recommend a compiler which detects this error?
Can you construct a test case which fails?
 
Can you construct a test case which fails?
Many apologies. It seems variable length arrays were added to C in the 1999 standard - a fact which has completely passed me by for getting on for 30 years.
They certainly weren't a thing in 1984 when I learnt about arrays and sizeof.
Going back to bed now...
 
Many apologies. It seems variable length arrays were added to C in the 1999 standard - a fact which has completely passed me by for getting on for 30 years.
They certainly weren't a thing in 1984 when I learnt about arrays and sizeof.
We still enforce C90 compliance at work (with the addition of long long type for 64 bit arithmetic) because a small number of the platforms we use have compilers that don't support anything newer. This is not uncommon in embedded work.
 
They certainly weren't a thing in 1984 when I learnt about arrays and sizeof.
The variable length arrays has been changed. Not sure whether I knew this. Probably not, it's a construction Ive not used in C - maybe in Java. But, in a simple test,
printf("%s %d\n",argv[1],sizeof(argv[1]));
the contents of argv[1] may vary but sizeof(argv[1]) is constant.
eg. test bull -> bull 8
test flobadob -> flobadob 8
So, you were correct about strlen vs sizeof.
 
Back
Top