TECLIB / CFPropertyList

PHP Implementation of Apple's PList (binary and xml)
http://teclib.github.io/CFPropertyList/
MIT License
454 stars 112 forks source link

CFPropertyList Problem #30

Closed ijo closed 9 years ago

ijo commented 9 years ago

Hello Folk. I have a little problem when using your library.

I'm using CFPropertyList to extract some binary data from plist saved in an ipad and use it in a web app. I save the data saved as a plist with php in a .plist file and then use

$plist = new CFPropertyList( dirname(FILE).'/sample.plist', CFPropertyList::FORMAT_BINARY );

I succesfully extracted the data almost all the times but when trying to read a .plist file that has 762KB it gives me an error. Do you have an idea of what is happening?

Thank you very much in advance for your time.

ckruse commented 9 years ago

Hm, can you upload an example plist? Is it only with binary plists or only with XML plists or with both?

Best regards, CK

lpotherat commented 9 years ago

I suggest also to share the error that it gives you, because "an error" could be everything.

ckruse commented 9 years ago

If it is a bplist: does it contain a very large dictionary?

ijo commented 9 years ago

Thanks for your comments. The error_log doesn't give any error, that's why it took me a little bit to realize that the error was when creating the new CFProperyList object.

Basically an iOS app writes a plist that it supossed to be binary in an sqlite file. Then, I read it doing a query an write the file sample.plist to the be readed by CFPropertyList. The code is the following:

$plist = new CFPropertyList( dirname(FILE).'/sample.plist', CFPropertyList::FORMAT_BINARY );

$plistarray = $plist->toArray();

$data_arr = ($plistarray['$objects']);

The curious thing is that when I write the sample.plist file for a certain configuration and this is about 320KB, the reading is succesful. However when the .plist is about 780KB it fails. The size depends of the configuration on how much data the ipad reads to then write to the sqlite file.

As I can't attach the .plist I'm posting the header and a little part of the information in it.

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

$archiver NSKeyedArchiver $objects $null $class CF$UID 32770 NS.objects CF$UID 2 Sorry if I'm not very explicit but I'm not an expert. Thank you very much.
ckruse commented 9 years ago

@ijo sent me the plist causing problems, and after spending yesterday evening with debugging I found the problem. The problem is that in plists as large as this one the object ref size might get bigger than 3 bytes; I didn't think of this. I will fix a push this evening.

ckruse commented 9 years ago

Hm, I was wrong. There is something else borky... looking for the problem again.

ckruse commented 9 years ago

Ok, I think I found the problem: the size was not the problem but it contained a uid type entry. It should work now, can you confirm?

ijo commented 9 years ago

Yes. Let me replace the library file. I'm curious because other files with less size also has uid types and they work.

Let me try and I'll email you.

On Wed, Jan 28, 2015 at 5:20 PM, Christian Kruse notifications@github.com wrote:

Ok, I think I found the problem: the size was not the problem but it contained a uid type entry. It should work now, can you confirm?

— Reply to this email directly or view it on GitHub https://github.com/rodneyrehm/CFPropertyList/issues/30#issuecomment-71937961 .

Ignacio J. Olivares

ijo commented 9 years ago

Now it throws the error:

Fatal error: Class 'CFPropertyList' not found in ------------/address.php on line 381

when I call: $plist = new CFPropertyList( dirname(FILE).'/sample.plist', CFPropertyList::FORMAT_BINARY );

On Wed, Jan 28, 2015 at 5:19 PM, Christian Kruse notifications@github.com wrote:

Closed #30 https://github.com/rodneyrehm/CFPropertyList/issues/30 via 2ea0483 https://github.com/rodneyrehm/CFPropertyList/commit/2ea0483806c989eb0518a767fa29a111bb29cb67 .

— Reply to this email directly or view it on GitHub https://github.com/rodneyrehm/CFPropertyList/issues/30#event-226472732.

Ignacio J. Olivares

ckruse commented 9 years ago

Are you sure that you correctly require() the classes/CFPropertyList/CFPropertyList.php file? This seems not to be an error on the library site, it seems as if the file hasn't been evaluated yet.

ijo commented 9 years ago

Don't know what's happening.

I'm using the same line as before: require_once(dirname(FILE).'/CFPropertyList/CFPropertyList.php');

And when I upload again the previous version of the classes it works.

The problem seems to be with the new CFPropertyList.php file.

ckruse commented 9 years ago

Hm, did you forget to import or mention the namespace? For me it simply works:

→ ckruse@sunshine ~  % git clone https://github.com/rodneyrehm/CFPropertyList.git
Cloning into 'CFPropertyList'...
remote: Counting objects: 400, done.
remote: Total 400 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (400/400), 81.58 KiB | 0 bytes/s, done.
Resolving deltas: 100% (218/218), done.
Checking connectivity... done.
→ ckruse@sunshine ~  % cat test.php                                              
<?php
require("./CFPropertyList/classes/CFPropertyList/CFPropertyList.php");
var_dump(new CFPropertyList\CFPropertyList());

→ ckruse@sunshine ~  % php test.php
object(CFPropertyList\CFPropertyList)#1 (18) {
  ["file":protected]=>
  NULL
  ["detectedFormat":protected]=>
  int(0)
  ["format":protected]=>
  int(0)
  ["value":protected]=>
  array(0) {
  }
  ["iteratorPosition":protected]=>
  int(0)
  ["iteratorKeys":protected]=>
  NULL
  ["content":protected]=>
  NULL
  ["pos":protected]=>
  int(0)
  ["uniqueTable":protected]=>
  array(0) {
  }
  ["countObjects":protected]=>
  int(0)
  ["stringSize":protected]=>
  int(0)
  ["intSize":protected]=>
  int(0)
  ["miscSize":protected]=>
  int(0)
  ["objectRefs":protected]=>
  int(0)
  ["writtenObjectCount":protected]=>
  int(0)
  ["objectTable":protected]=>
  array(0) {
  }
  ["objectRefSize":protected]=>
  int(0)
  ["offsets":protected]=>
  array(0) {
  }
}
→ ckruse@sunshine ~  % 
ijo commented 9 years ago

Now is working but I had to change the object creation from: $plist = new CFPropertyList( dirname(FILE).'/sample.plist', CFPropertyList::FORMAT_BINARY ); to: $plist = new CFPropertyList\CFPropertyList( dirname(FILE).'/sample.plist');

so the optional parameter that specifies the type of the file is giving me problems.

Thank you very much for all your help Christian.

ckruse commented 9 years ago

Hi,

Ignacio Olivares notifications@github.com writes:

Now is working but I had to change the object creation from: $plist = new CFPropertyList( dirname(FILE).'/sample.plist', CFPropertyList::FORMAT_BINARY ); to: $plist = new CFPropertyList\CFPropertyList( dirname(FILE).'/sample.plist');

so the optional parameter that specifies the type of the file is giving me problems.

Did you use a full qualified name? Like this:

$plist = new CFPropertyList\CFPropertyList(dirname(__FILE__).'/sample.plist', CFPropertyList\CFPropertyList::FORMAT_BINARY);

You could also import the namespace using the use namespace.

Thank you very much for all your help Christian.

You're very welcome!

Regards,

Christian Kruse http://ck.kennt-wayne.de/