bugfix for [#23737] reported by Mariusz Maximus
netrender client's functions to get slaves and jobs info didn't work anymore (was reading response content twice). At the same time, I switched to json for the dump and load, instead of using eval and repr (for obvious security reasons). I should have done this much earlier.
This commit is contained in:
@@ -20,6 +20,7 @@ import bpy
|
||||
import sys, os, re
|
||||
import http, http.client, http.server, urllib
|
||||
import subprocess, shutil, time, hashlib
|
||||
import json
|
||||
|
||||
import netrender
|
||||
import netrender.model
|
||||
@@ -169,7 +170,7 @@ def clientSendJob(conn, scene, anim = False):
|
||||
job.priority = netsettings.priority
|
||||
|
||||
# try to send path first
|
||||
conn.request("POST", "/job", repr(job.serialize()))
|
||||
conn.request("POST", "/job", json.dumps(job.serialize()))
|
||||
response = conn.getresponse()
|
||||
response.read()
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import http, http.client, http.server, urllib, socket, socketserver, threading
|
||||
import subprocess, shutil, time, hashlib
|
||||
import pickle
|
||||
import select # for select.error
|
||||
import json
|
||||
|
||||
from netrender.utils import *
|
||||
import netrender.model
|
||||
@@ -90,7 +91,7 @@ class MRenderJob(netrender.model.RenderJob):
|
||||
def save(self):
|
||||
if self.save_path:
|
||||
f = open(os.path.join(self.save_path, "job.txt"), "w")
|
||||
f.write(repr(self.serialize()))
|
||||
f.write(json.dumps(self.serialize()))
|
||||
f.close()
|
||||
|
||||
def edit(self, info_map):
|
||||
@@ -384,7 +385,7 @@ class RenderHandler(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
self.server.stats("", "Sending status")
|
||||
self.send_head()
|
||||
self.wfile.write(bytes(repr(message), encoding='utf8'))
|
||||
self.wfile.write(bytes(json.dumps(message), encoding='utf8'))
|
||||
|
||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
elif self.path == "/job":
|
||||
@@ -410,7 +411,7 @@ class RenderHandler(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
message = job.serialize(frames)
|
||||
|
||||
self.wfile.write(bytes(repr(message), encoding='utf8'))
|
||||
self.wfile.write(bytes(json.dumps(message), encoding='utf8'))
|
||||
|
||||
self.server.stats("", "Sending job to slave")
|
||||
else:
|
||||
@@ -468,7 +469,7 @@ class RenderHandler(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
self.send_head()
|
||||
|
||||
self.wfile.write(bytes(repr(message), encoding='utf8'))
|
||||
self.wfile.write(bytes(json.dumps(message), encoding='utf8'))
|
||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
else:
|
||||
# hand over the rest to the html section
|
||||
@@ -486,7 +487,7 @@ class RenderHandler(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
length = int(self.headers['content-length'])
|
||||
|
||||
job_info = netrender.model.RenderJob.materialize(eval(str(self.rfile.read(length), encoding='utf8')))
|
||||
job_info = netrender.model.RenderJob.materialize(json.loads(str(self.rfile.read(length), encoding='utf8')))
|
||||
|
||||
job_id = self.server.nextJobID()
|
||||
|
||||
@@ -657,7 +658,7 @@ class RenderHandler(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
self.server.stats("", "New slave connected")
|
||||
|
||||
slave_info = netrender.model.RenderSlave.materialize(eval(str(self.rfile.read(length), encoding='utf8')), cache = False)
|
||||
slave_info = netrender.model.RenderSlave.materialize(json.loads(str(self.rfile.read(length), encoding='utf8')), cache = False)
|
||||
|
||||
slave_id = self.server.addSlave(slave_info.name, self.client_address, slave_info.stats)
|
||||
|
||||
@@ -666,7 +667,7 @@ class RenderHandler(http.server.BaseHTTPRequestHandler):
|
||||
elif self.path == "/log":
|
||||
length = int(self.headers['content-length'])
|
||||
|
||||
log_info = netrender.model.LogFile.materialize(eval(str(self.rfile.read(length), encoding='utf8')))
|
||||
log_info = netrender.model.LogFile.materialize(json.loads(str(self.rfile.read(length), encoding='utf8')))
|
||||
|
||||
slave_id = log_info.slave_id
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import bpy
|
||||
import sys, os
|
||||
import http, http.client, http.server, urllib, socket
|
||||
import webbrowser
|
||||
import json
|
||||
|
||||
import netrender
|
||||
from netrender.utils import *
|
||||
@@ -205,10 +206,10 @@ class RENDER_OT_netclientstatus(bpy.types.Operator):
|
||||
conn.request("GET", "/status")
|
||||
|
||||
response = conn.getresponse()
|
||||
response.read()
|
||||
content = response.read()
|
||||
print( response.status, response.reason )
|
||||
|
||||
jobs = (netrender.model.RenderJob.materialize(j) for j in eval(str(response.read(), encoding='utf8')))
|
||||
jobs = (netrender.model.RenderJob.materialize(j) for j in json.loads(str(content, encoding='utf8')))
|
||||
|
||||
while(len(netsettings.jobs) > 0):
|
||||
netsettings.jobs.remove(0)
|
||||
@@ -307,10 +308,10 @@ class RENDER_OT_netclientslaves(bpy.types.Operator):
|
||||
conn.request("GET", "/slaves")
|
||||
|
||||
response = conn.getresponse()
|
||||
response.read()
|
||||
content = response.read()
|
||||
print( response.status, response.reason )
|
||||
|
||||
slaves = (netrender.model.RenderSlave.materialize(s) for s in eval(str(response.read(), encoding='utf8')))
|
||||
slaves = (netrender.model.RenderSlave.materialize(s) for s in json.loads(str(content, encoding='utf8')))
|
||||
|
||||
while(len(netsettings.slaves) > 0):
|
||||
netsettings.slaves.remove(0)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import sys, os, platform, shutil
|
||||
import http, http.client, http.server, urllib
|
||||
import subprocess, time
|
||||
import json
|
||||
|
||||
from netrender.utils import *
|
||||
import netrender.model
|
||||
@@ -111,7 +112,7 @@ def render_slave(engine, netsettings, threads):
|
||||
conn = clientConnection(netsettings.server_address, netsettings.server_port)
|
||||
|
||||
if conn:
|
||||
conn.request("POST", "/slave", repr(slave_Info().serialize()))
|
||||
conn.request("POST", "/slave", json.dumps(slave_Info().serialize()))
|
||||
response = conn.getresponse()
|
||||
response.read()
|
||||
|
||||
@@ -130,7 +131,7 @@ def render_slave(engine, netsettings, threads):
|
||||
if response.status == http.client.OK:
|
||||
timeout = 1 # reset timeout on new job
|
||||
|
||||
job = netrender.model.RenderJob.materialize(eval(str(response.read(), encoding='utf8')))
|
||||
job = netrender.model.RenderJob.materialize(json.loads(str(response.read(), encoding='utf8')))
|
||||
engine.update_stats("", "Network render processing job from master")
|
||||
|
||||
JOB_PREFIX = os.path.join(NODE_PREFIX, "job_" + job.id)
|
||||
@@ -156,7 +157,7 @@ def render_slave(engine, netsettings, threads):
|
||||
|
||||
# announce log to master
|
||||
logfile = netrender.model.LogFile(job.id, slave_id, [frame.number for frame in job.frames])
|
||||
conn.request("POST", "/log", bytes(repr(logfile.serialize()), encoding='utf8'))
|
||||
conn.request("POST", "/log", bytes(json.dumps(logfile.serialize()), encoding='utf8'))
|
||||
response = conn.getresponse()
|
||||
response.read()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user